<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!-- 2016-07-28 Thu 02:18 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>小蟬 / cicada-nymph</title>
<meta name="generator" content="Org-mode" />
<meta name="author" content="謝宇恆 / XIE Yuheng" />
<link rel="stylesheet" href="https://xieyuheng.github.io/asset/css/page.css" type="text/css" media="screen" />
<script type="text/javascript">
/*
@licstart  The following is the entire license notice for the
JavaScript code in this tag.

Copyright (C) 2012-2013 Free Software Foundation, Inc.

The JavaScript code in this tag is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version.  The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.  See the GNU GPL for more details.

As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.


@licend  The above is the entire license notice
for the JavaScript code in this tag.
*/
<!--/*--><![CDATA[/*><!--*/
 function CodeHighlightOn(elem, id)
 {
   var target = document.getElementById(id);
   if(null != target) {
     elem.cacheClassElem = elem.className;
     elem.cacheClassTarget = target.className;
     target.className = "code-highlighted";
     elem.className   = "code-highlighted";
   }
 }
 function CodeHighlightOff(elem, id)
 {
   var target = document.getElementById(id);
   if(elem.cacheClassElem)
     elem.className = elem.cacheClassElem;
   if(elem.cacheClassTarget)
     target.className = elem.cacheClassTarget;
 }
/*]]>*///-->
</script>
</head>
<body>
<div id="preamble" class="status">
近死之心 莫使復陽也
</div>
<div id="content">
<h1 class="title">小蟬 / cicada-nymph</h1>
<div id="table-of-contents">
<h2>overview</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#orga27444d"><span class="done todo">todo</span> </a>
<ul>
<li><a href="#org45c1bbd">add length field into jo in assembly code&#xa0;&#xa0;&#xa0;<span class="tag"><span class="maybe">maybe</span></span></a></li>
<li><a href="#org5bd126b">memory&#xa0;&#xa0;&#xa0;<span class="tag"><span class="limit">limit</span></span></a></li>
<li><a href="#orgfc2a140">reading-stack&#xa0;&#xa0;&#xa0;<span class="tag"><span class="limit">limit</span></span></a></li>
<li><a href="#org73bcf7b">div&#xa0;&#xa0;&#xa0;<span class="tag"><span class="bug">bug</span></span></a></li>
<li><a href="#orgd8b135">stack&#xa0;&#xa0;&#xa0;<span class="tag"><span class="limit">limit</span></span></a></li>
<li><a href="#org1a6e822">string-reverse!&#xa0;&#xa0;&#xa0;<span class="tag"><span class="bug">bug</span></span></a></li>
</ul>
</li>
<li><a href="#org2a89c7f">prolog</a>
<ul>
<li><a href="#org64586e9"><span class="todo note">note</span> conditional preprocessing</a></li>
<li><a href="#orgf661c18">platform configuration</a></li>
<li><a href="#org2277e96">misc</a></li>
<li><a href="#orgcd521d6">cell_size&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></a></li>
<li><a href="#orga1ff92b">cell_size&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></a></li>
<li><a href="#org8403cae">header&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span>&#xa0;<span class="linux">linux</span></span></a></li>
<li><a href="#orgff479c1">format&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span>&#xa0;<span class="linux">linux</span></span></a></li>
<li><a href="#org55a5623">entry&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span>&#xa0;<span class="linux">linux</span></span></a></li>
<li><a href="#org17a955b">header&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span>&#xa0;<span class="linux">linux</span></span></a></li>
<li><a href="#orge8cac7c">format&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span>&#xa0;<span class="linux">linux</span></span></a></li>
<li><a href="#org875ea93">entry&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span>&#xa0;<span class="linux">linux</span></span></a></li>
<li><a href="#org897c344">memory allocation in un_initialized_memory</a></li>
</ul>
</li>
<li><a href="#org96d9b81">argument-stack</a>
<ul>
<li><a href="#orgd7c52ca"><span class="todo note">note</span> stack</a></li>
<li><a href="#org84d762">memory allocation</a></li>
<li><a href="#orgf0b6cf1">pointer&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></a></li>
<li><a href="#orga155ead">push &amp; pop&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></a></li>
<li><a href="#org1a87a91">pointer&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></a></li>
<li><a href="#org98133d5">push &amp; pop&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></a></li>
</ul>
</li>
<li><a href="#org64020d4">return-stack</a>
<ul>
<li><a href="#org7ee867e"><span class="todo _">記</span> </a></li>
<li><a href="#orgbfad70">memory allocation</a></li>
<li><a href="#org2898d45">pointer&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></a></li>
<li><a href="#orga9edac5">push &amp; pop&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></a></li>
<li><a href="#orge5102f3">pointer&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></a></li>
<li><a href="#org4477a8d">push &amp; pop&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></a></li>
</ul>
</li>
<li><a href="#org4b4d0f0">next</a>
<ul>
<li><a href="#orgd6112ae">macro next</a></li>
<li><a href="#org60e653a"><span class="todo note">note</span> play with jo &amp; jojo</a></li>
</ul>
</li>
<li><a href="#org7daaf22">function-jo</a>
<ul>
<li><a href="#orgdbbb7d2"><span class="todo note">note</span> jo</a></li>
<li><a href="#orgd5f5ecb">offset of jo</a></li>
<li><a href="#org8851c88"><span class="todo note">note</span> link</a></li>
<li><a href="#org994cbb9">offset of link</a></li>
<li><a href="#org245ef4">null link</a></li>
<li><a href="#org32f474e"><b>string-area</b></a>
<ul>
<li><a href="#orgacfb46">memory allocation</a></li>
<li><a href="#org2837e17">ASSEMBLY__length_string</a></li>
<li><a href="#orgaaef7d9">ASSEMBLY__make_string</a></li>
</ul>
</li>
<li><a href="#org16111ff"><span class="todo note">note</span> </a></li>
<li><a href="#orgf3dcfe5">define_function</a></li>
<li><a href="#org2f493c5">explain$function</a></li>
</ul>
</li>
<li><a href="#org65852ef">primitive-function-jo</a>
<ul>
<li><a href="#org24601b6"><span class="todo note">note</span> </a></li>
<li><a href="#orga8b41e8">define_primitive_function</a></li>
</ul>
</li>
<li><a href="#org5684749">variable-jo</a>
<ul>
<li><a href="#org7f78325"><span class="todo note">note</span> </a></li>
<li><a href="#orgd57b258">define_variable</a></li>
<li><a href="#org966f410">explain$variable&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></a></li>
<li><a href="#org8117cc9">explain$variable&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></a></li>
</ul>
</li>
<li><a href="#org6616390">jo</a>
<ul>
<li><a href="#org4dd034e">apply</a></li>
<li><a href="#org9bfd5e4"><b>cell-size</b></a></li>
<li><a href="#orgd6afee8">jo-&gt;explainer</a></li>
<li><a href="#org61e9782">jo-&gt;length</a></li>
<li><a href="#org8274059">jo,set-length</a></li>
<li><a href="#org93e077f">jo-&gt;body</a></li>
<li><a href="#orge10e831">primitive-function-jo?</a></li>
<li><a href="#orgaf3016">function-jo?</a></li>
<li><a href="#org6376de0">variable-jo?</a></li>
<li><a href="#orge238ac4">variable-jo-&gt;address</a></li>
</ul>
</li>
<li><a href="#org931bab6">string-area</a>
<ul>
<li><a href="#org7c60b12"><span class="todo note">note</span> interface</a></li>
<li><a href="#org89f8802"><b>string-area</b></a></li>
<li><a href="#orgeecc98">string-area,stay</a></li>
<li><a href="#org9a2819d">make-string</a></li>
</ul>
</li>
<li><a href="#orga454a1d">return-stack</a>
<ul>
<li><a href="#org8b8184c"><span class="todo note">note</span> return-point</a></li>
<li><a href="#org95e3652">offset of return-point</a></li>
<li><a href="#org314ce79">return-stack:*unit*</a></li>
<li><a href="#orgb4cd77"><span class="todo _">記</span> 插 珠珠 人返回棧 到某珠珠的前面 [等效替換法 以理解]</a></li>
<li><a href="#org21a7811">nothing</a></li>
<li><a href="#orgc64671b">return-stack:insert-jo</a></li>
<li><a href="#org51ae31a">get-return-stack-pointer</a></li>
<li><a href="#orgb7a880">apply-with-return-point</a></li>
</ul>
</li>
<li><a href="#org53b6a21">end &amp; tail-call</a>
<ul>
<li><a href="#orge8bd83c">end</a></li>
<li><a href="#orgf01085d">tail-call</a></li>
<li><a href="#orgbdf3567"><span class="todo note">note</span> explicit tail call in action</a></li>
</ul>
</li>
<li><a href="#org7fac706">helper function in assembly code</a>
<ul>
<li><a href="#orga2edc1a">__exit_with_tos&#xa0;&#xa0;&#xa0;<span class="tag"><span class="linux">linux</span></span></a></li>
<li><a href="#org494bb2d">__exit_with_zero&#xa0;&#xa0;&#xa0;<span class="tag"><span class="linux">linux</span></span></a></li>
<li><a href="#org2b92416">__exit_with_six&#xa0;&#xa0;&#xa0;<span class="tag"><span class="linux">linux</span></span></a></li>
<li><a href="#org3fd2b0a">__write_string&#xa0;&#xa0;&#xa0;<span class="tag"><span class="linux">linux</span></span></a></li>
<li><a href="#org830074">__reset_argument_stack&#xa0;&#xa0;&#xa0;<span class="tag"><span class="linux">linux</span></span></a></li>
<li><a href="#orge1bcb73">__reset_return_stack&#xa0;&#xa0;&#xa0;<span class="tag"><span class="linux">linux</span></span></a></li>
<li><a href="#org51ec906">__reset_syntax_stack&#xa0;&#xa0;&#xa0;<span class="tag"><span class="linux">linux</span></span></a></li>
<li><a href="#orgbb189e4">__reset_local_variable</a></li>
<li><a href="#org42b0707">__reset_local_memory</a></li>
</ul>
</li>
<li><a href="#org65e5db0"><b>the-story-begin</b></a>
<ul>
<li><a href="#org91ce231"><span class="todo _">記</span> 匯編代碼中的初始化</a></li>
<li><a href="#org1b06f40">begin_to_interpret_threaded_code&#xa0;&#xa0;&#xa0;<span class="tag"><span class="linux">linux</span></span></a></li>
<li><a href="#orga5136c3">initialization</a></li>
<li><a href="#org3cfdb28"><span class="todo note">note</span> top-level-REPL</a></li>
<li><a href="#org43952a9">report-return-stack-is-empty-and-exit</a></li>
<li><a href="#org78b3e3d">reset-top-level-REPL</a></li>
<li><a href="#org7118f6a">exit_with_tos a.k.a. bye</a></li>
<li><a href="#org9e400e5">little_test</a></li>
</ul>
</li>
<li><a href="#org9979052">instruction</a>
<ul>
<li><a href="#orgf896f91"><span class="todo note">note</span> side-effect</a></li>
<li><a href="#org8c93430"><span class="todo note">note</span> naming</a></li>
<li><a href="#orga9c1146">instruction,literal</a></li>
<li><a href="#org761f66">instruction,address</a></li>
<li><a href="#orgfce615c">instruction,branch</a></li>
<li><a href="#org75ea086">instruction,false?branch</a></li>
</ul>
</li>
<li><a href="#orgb634106">the stack</a>
<ul>
<li><a href="#orga60f966"><span class="todo note">note</span> </a></li>
<li><a href="#org25675f4">drop</a></li>
<li><a href="#org95f768e">dup&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></a></li>
<li><a href="#orgf4db053">dup&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></a></li>
<li><a href="#orgcec814b">over&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></a></li>
<li><a href="#org70c0abf">over&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></a></li>
<li><a href="#org9caf9fa">tuck</a></li>
<li><a href="#org5656ea0">swap</a></li>
<li><a href="#org81127fe">address</a></li>
<li><a href="#org350be05">pointer</a></li>
<li><a href="#org8ac64f2">set-argument-stack-pointer</a></li>
</ul>
</li>
<li><a href="#orgf29e76f">bool</a>
<ul>
<li><a href="#org8b60876">false &amp; true</a></li>
<li><a href="#org4eb5b23">false? &amp; true?</a></li>
<li><a href="#orgac6c0b9">and &amp; or &amp; not &amp; xor</a></li>
</ul>
</li>
<li><a href="#org6c162c9">fixnum</a>
<ul>
<li><a href="#orgcc1e604">zero &amp; one</a></li>
<li><a href="#orgc5fca29">zero? &amp; one?</a></li>
<li><a href="#orgb88f754">add &amp; sub&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></a></li>
<li><a href="#org7956798">add &amp; sub&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></a></li>
<li><a href="#org32f9827">mul</a></li>
<li><a href="#org7211326">negate</a></li>
<li><a href="#org291a842">power</a></li>
<li><a href="#orga5a01e4">div &amp; mod</a></li>
<li><a href="#org1b521f6">equal? &amp; greater-than? &amp; less-than?</a></li>
<li><a href="#orgfbda9e3">equal2?</a></li>
<li><a href="#org6c71623">negative? &amp; positive?</a></li>
<li><a href="#org64fa053">within?</a></li>
<li><a href="#org8b0c953"><span class="done test">test</span> </a></li>
</ul>
</li>
<li><a href="#org7325ce4">memory</a>
<ul>
<li><a href="#org3193e62"><span class="todo note">note</span> get &amp; set</a></li>
<li><a href="#org2ea6378"><span class="todo note">note</span> endianness of n-get &amp; n-set</a></li>
<li><a href="#org3c101e2">get&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></a></li>
<li><a href="#orgcd01e4">set&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></a></li>
<li><a href="#org6dde778">get&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></a></li>
<li><a href="#org9a6bad1">set&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></a></li>
<li><a href="#org5984fca">clear</a></li>
</ul>
</li>
<li><a href="#org69bb1f1">bit</a>
<ul>
<li><a href="#org5c163de"><span class="todo note">note</span> </a></li>
<li><a href="#org6cbd36c">or &amp; and &amp; xor &amp; invert&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></a></li>
<li><a href="#org216c4a9">or &amp; and &amp; xor &amp; invert&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></a></li>
<li><a href="#org97d44dd">left &amp; right[,sign]</a></li>
<li><a href="#orgcd2a178">get &amp; set &amp; clear &amp; invert</a></li>
<li><a href="#org77ef079">find-[lowest|highest]-set-bit</a></li>
<li><a href="#orgac93810"><span class="done test">test</span> </a></li>
</ul>
</li>
<li><a href="#orgc0355d9">write-byte</a>
<ul>
<li><a href="#org5d7a8f9">write-byte&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span>&#xa0;<span class="linux">linux</span></span></a></li>
<li><a href="#orgb063a31">write-byte&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span>&#xa0;<span class="linux">linux</span></span></a></li>
</ul>
</li>
<li><a href="#orgcbd72a1">reading-stack</a>
<ul>
<li><a href="#org4d3f530"><span class="todo note">note</span> </a></li>
<li><a href="#orgd655150">memory allocation</a></li>
<li><a href="#org79c80a9">push &amp; pop &amp; drop&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></a></li>
<li><a href="#org27a939c">push &amp; pop &amp; drop&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></a></li>
<li><a href="#orgc6273aa">tos</a></li>
<li><a href="#org3df3f05">reading-stack-empty?</a></li>
</ul>
</li>
<li><a href="#orgc07c3f9">read-byte</a>
<ul>
<li><a href="#orgee0832"><span class="todo note">note</span> end of file</a></li>
<li><a href="#orge656079"><span class="todo note">note</span> factoring</a></li>
<li><a href="#orgc77e82f">read-line-from-stdin&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span>&#xa0;<span class="linux">linux</span></span></a></li>
<li><a href="#org7b8311">read-line-from-stdin&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span>&#xa0;<span class="linux">linux</span></span></a></li>
<li><a href="#org732a663"><span class="done test">test</span> read-line-from-stdin</a></li>
<li><a href="#orgea3ae1b">read-byte</a></li>
</ul>
</li>
<li><a href="#orgf9c337e">load-core-file</a></li>
<li><a href="#orgc1cf5a1">byte</a>
<ul>
<li><a href="#org762ce7c">space-byte?</a></li>
<li><a href="#orga43063f">bar-ket-byte?</a></li>
<li><a href="#orgb485ae1">digit-byte?</a></li>
<li><a href="#org281a9cf">digit-byte-&gt;number &amp; number-&gt;digit-byte</a></li>
</ul>
</li>
<li><a href="#org7e84198">buffer</a>
<ul>
<li><a href="#orgf962804"><span class="todo note">note</span> </a></li>
<li><a href="#orga9b45d8">compare-buffer</a></li>
<li><a href="#org988a4fe">cursor-&gt;next-matching-byte</a></li>
</ul>
</li>
<li><a href="#org5a87b1e">string</a>
<ul>
<li><a href="#orgf212cde"><span class="todo note">note</span> io about string</a></li>
<li><a href="#org77c5d74">write-string</a></li>
<li><a href="#orgfab5f36">pretty_write_string</a></li>
<li><a href="#org801cbe4">string:empty?</a></li>
<li><a href="#org2a47304">string:equal?</a></li>
<li><a href="#org5f47d33">string:byte</a></li>
<li><a href="#org4049599">string:byte-tail</a></li>
<li><a href="#org7d68499">string:byte-back</a></li>
<li><a href="#org47630ca">string-&gt;buffer!</a></li>
<li><a href="#orgc1d10ef">string-reverse!&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></a></li>
<li><a href="#org4044070">string-reverse!&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></a></li>
<li><a href="#orgd3f1316">one-byte-string?</a></li>
<li><a href="#orgf3bc476">zero-string?</a></li>
<li><a href="#orgc94e208">digit-string?</a></li>
<li><a href="#org8e895f3">integer-string?</a></li>
<li><a href="#org24fe7cc">digit-string-&gt;number</a></li>
<li><a href="#orge161bc3">string-&gt;integer</a></li>
<li><a href="#org7a74f3b">string:find-byte</a></li>
<li><a href="#org1dc900c"><span class="done test">test</span> </a></li>
<li><a href="#orgfc92b03">string-end,byte</a></li>
<li><a href="#org6fc80bb"><span class="todo note">note</span> </a></li>
<li><a href="#orgfb1ed7a">string:space?</a></li>
<li><a href="#org37f1f47">string:word-begin</a></li>
<li><a href="#org936a7b7">string:word-end</a></li>
<li><a href="#orgb45825b">string:word</a></li>
<li><a href="#org53a871f">string:word-tail</a></li>
</ul>
</li>
<li><a href="#org530af3b">write number</a>
<ul>
<li><a href="#orgb5226b5">write-number</a></li>
<li><a href="#org9dea4d7">write-integer</a></li>
<li><a href="#org7fc156b">pretty_write_integer</a></li>
</ul>
</li>
<li><a href="#org2305b22">word</a>
<ul>
<li><a href="#org3d4965e"><span class="todo note">note</span> io about word</a></li>
<li><a href="#org3a23795"><span class="todo note">note</span> bar-ket</a></li>
<li><a href="#org6b276da">memory allocation</a></li>
<li><a href="#org31bc39d">read-word-&gt;buffer</a></li>
<li><a href="#org4a6ee9b">read-word</a></li>
</ul>
</li>
<li><a href="#org235633e">link</a>
<ul>
<li><a href="#org466f0a1">last-link?</a></li>
<li><a href="#org2cdf0f1">link-&gt;next-link</a></li>
<li><a href="#org485f6c">link-&gt;name-string</a></li>
<li><a href="#orgad42f93">link-&gt;jo</a></li>
<li><a href="#org4354d3">link,set-jo</a></li>
<li><a href="#orgdf8e244"><b>link</b></a></li>
<li><a href="#orge365ca8"><span class="todo note">note</span> about find</a></li>
<li><a href="#org99a163c"><span class="todo _">記</span> 遍歷鏈表的方式</a></li>
<li><a href="#orga76c9d">find-link</a></li>
</ul>
</li>
<li><a href="#org9ed96e4">basic-REPL</a>
<ul>
<li><a href="#org78d5cd7">word-interpreter</a></li>
<li><a href="#orgfe4f120">basic-REPL</a></li>
</ul>
</li>
<li><a href="#org2e7af8b">colon semicolon</a>
<ul>
<li><a href="#org9a75f2c"><span class="todo note">note</span> </a></li>
<li><a href="#orge3f9a9d">[colon|semicolon]-string?</a></li>
<li><a href="#orgb866435">comment-[begin|end]-string?</a></li>
<li><a href="#orgbbdb82e">colon &amp; semicolon</a></li>
<li><a href="#orgd66f701">ignore-comment</a></li>
<li><a href="#org4c0c4f4"><span class="done test">test</span> </a></li>
</ul>
</li>
<li><a href="#org6f7d4a2">jojo-area</a>
<ul>
<li><a href="#orgd662b74"><span class="todo note">note</span> </a></li>
<li><a href="#org90ce64">memory allocation</a></li>
<li><a href="#orgc32cd41">jojo-area,stay</a></li>
</ul>
</li>
<li><a href="#org947123">make-link</a></li>
<li><a href="#org3e68ae6">make-jo-head</a></li>
<li><a href="#orgbe79f82">syntax-stack</a>
<ul>
<li><a href="#orgdcf84cb"><span class="todo _">記</span> </a></li>
<li><a href="#org80bd8fb">memory allocate</a></li>
<li><a href="#orgf0262f5">push-syntax-stack</a></li>
<li><a href="#org6b33a79">pop-syntax-stack</a></li>
<li><a href="#orgfbe7dd0">tos-syntax-stack</a></li>
<li><a href="#orgbfd3d16">drop-syntax-stack</a></li>
<li><a href="#orgad8f2e7">syntax-stack-empty?</a></li>
<li><a href="#org20d6ed2">find-syntax</a></li>
</ul>
</li>
<li><a href="#org5c361a6">syntax-rule-set</a>
<ul>
<li><a href="#org3396e3d"><span class="todo _">記</span> 使用</a></li>
<li><a href="#orga360c3c"><span class="todo note">note</span> border</a></li>
<li><a href="#orgfd196c5"><span class="todo _">記</span> interface</a></li>
<li><a href="#org8b4e4c8">syntax-rule:*unit*</a></li>
<li><a href="#org3e88744">syntax-rule:get-predicate</a></li>
<li><a href="#orgec7cb95">syntax-rule:get-function</a></li>
<li><a href="#org83a85ec">syntax-rule:get</a></li>
<li><a href="#orgb090c98">syntax-rule-set:get-border</a></li>
<li><a href="#orgab651c0">syntax-rule-set:set-border</a></li>
<li><a href="#org749d337">syntax-rule:add</a></li>
<li><a href="#org701bbef">syntax-rule-set:find</a></li>
</ul>
</li>
<li><a href="#orgd17150a">jojo-compiler:*syntax-rule-set*</a>
<ul>
<li><a href="#orgb22a029"><span class="todo note">note</span> </a></li>
<li><a href="#orgd892642">jojo-compiler-syntax:integer-string</a></li>
<li><a href="#org31f40ce">literal-word:address?</a></li>
<li><a href="#orgbf4c94c">jojo-compiler-syntax:address</a></li>
<li><a href="#org410343e">literal-word:jo?</a></li>
<li><a href="#org6ccc610">jojo-compiler-syntax:jo</a></li>
<li><a href="#org92bb4d1">literal-word:double-quote?</a></li>
<li><a href="#org4c7b403">syntax,double-quote,jojo-compiler</a></li>
<li><a href="#orgad1b185"><span class="todo note">note</span> </a></li>
<li><a href="#orgdc6e51e">syntax,comment,jojo-compiler</a></li>
<li><a href="#orgc37e0a3">memory allocation</a></li>
<li><a href="#org757600b">jojo-compiler:*syntax-rule-set*</a></li>
<li><a href="#org656395c">init,syntax-rule-set:jojo-compiler</a></li>
</ul>
</li>
<li><a href="#org5a64627">jojo-compiler</a>
<ul>
<li><a href="#org1fba1e1"><span class="todo note">note</span> </a></li>
<li><a href="#org9aff250">jojo-compiler,dispatch-word</a></li>
<li><a href="#org4438378">jojo-compiler</a></li>
</ul>
</li>
<li><a href="#orga1e7859">define-function</a>
<ul>
<li><a href="#orgca0225a"><span class="todo note">note</span> </a></li>
<li><a href="#orgf332061">define-function</a></li>
<li><a href="#org7faa1b7"><span class="done test">test</span> </a></li>
<li><a href="#org752d8f2"><span class="done test">test</span> double-quote</a></li>
</ul>
</li>
<li><a href="#orgc85753a">define-variable,with-tos</a>
<ul>
<li><a href="#org733fbf4">define-variable,with-tos</a></li>
<li><a href="#org20558be"><span class="done test">test</span> </a></li>
</ul>
</li>
<li><a href="#orgaa8a50d"><b>local-variable</b></a>
<ul>
<li><a href="#org7bc80d1"><span class="todo _">記</span> 有名字的局部變量 與 變長的局部數據</a></li>
<li><a href="#orgc122860"><span class="todo _">記</span> 再增加局部變元支持之後 需要重寫的部分</a>
<ul>
<li><a href="#org44ecbef">詮釋者 與 收尾詞</a></li>
<li><a href="#org8fc1e16">語法擴展方面的支持</a></li>
</ul>
</li>
<li><a href="#org291d9b4"><span class="todo _">記</span> 總結</a>
<ul>
<li><a href="#orga393bd2">interface</a></li>
<li><a href="#org2246b7d">語義特點總結</a></li>
<li><a href="#orgb7e1b4e">語用特點總結</a></li>
</ul>
</li>
<li><a href="#org29d6a3f"><span class="todo _">記</span> 關於分支結構</a></li>
<li><a href="#org8ea7fa">memory allocation</a></li>
<li><a href="#org56b55a2"><span class="todo _">記</span> 注意結尾詞會初始化局部變量指針</a></li>
<li><a href="#org700f0fc">allocate-local-variable</a></li>
<li><a href="#org75b80aa"><span class="todo note">note</span> many get &amp; set</a></li>
<li><a href="#orgb01ebd">instruction,local-variable,[n-get|n-set]&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></a></li>
<li><a href="#org4a121ee">instruction,local-variable,[n-get|n-set]&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></a></li>
<li><a href="#orgb567284"><span class="todo note">note</span> example result</a></li>
<li><a href="#orgbbd6bfe"><span class="done test">test</span> </a></li>
<li><a href="#org8b46ad8"><span class="done test">test</span> nested call</a></li>
<li><a href="#orgb1f9bd9"><span class="todo _">記</span> 問題</a>
<ul>
<li><a href="#org243fff0">nested block</a></li>
<li><a href="#org7a406c5">branch</a></li>
</ul>
</li>
<li><a href="#orgf0091a0">local-variable-table</a>
<ul>
<li><a href="#org990a0bc"><span class="todo _">記</span> </a></li>
<li><a href="#org4ceb115"><span class="todo _">記</span> 接口</a></li>
<li><a href="#orgb56c063">memory allocation</a></li>
<li><a href="#orgf8211ec">local-variable-table,clear</a></li>
<li><a href="#orga312bad">local-variable-table,insert</a></li>
<li><a href="#orgd07431d">local-variable-table,find</a></li>
<li><a href="#org47a30d8">count-front-colon</a></li>
</ul>
</li>
<li><a href="#orga240090">two syntaxes</a>
<ul>
<li><a href="#org9751635">local-variable-get-word?</a></li>
<li><a href="#org93f4856">jojo-compiler-syntax:local-variable-get</a></li>
<li><a href="#org27232be">local-variable-set-word?</a></li>
<li><a href="#orge896885">jojo-compiler-syntax:local-variable-set</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#orgf9d9978"><b>local-memory</b></a>
<ul>
<li><a href="#org3020c92"><span class="todo _">記</span> </a></li>
<li><a href="#orgb0073e5"><span class="todo _">記</span> 使用</a></li>
<li><a href="#org569a159"><b>local-memory-even</b></a></li>
<li><a href="#orgcac0793"><b>local-memory-odd</b></a></li>
<li><a href="#org20074ce"><span class="todo _">記</span> 奇偶性</a></li>
<li><a href="#org8c29d59">allocate-local-memory</a></li>
<li><a href="#org7bf71e9">allocate-conjugate-local-memory</a></li>
<li><a href="#orgf632b10"><span class="done test">test</span> </a></li>
</ul>
</li>
<li><a href="#orgc78f3ba">syscall</a>
<ul>
<li><a href="#orga79c513"><span class="todo note">note</span> </a></li>
<li><a href="#org5c326ed">string-&gt;syscall-string</a></li>
<li><a href="#org8cbd323">string-&gt;syscall-string-2</a></li>
<li><a href="#org3895db0">syscall&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span>&#xa0;<span class="linux">linux</span></span></a></li>
<li><a href="#org799e6a1">syscall&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span>&#xa0;<span class="linux">linux</span></span></a></li>
</ul>
</li>
<li><a href="#org288a128">epilog</a>
<ul>
<li><a href="#orgeed509d">constant</a></li>
<li><a href="#org4d234b6">platform</a></li>
<li><a href="#org5849a23"><b>un-initialized-memory</b></a></li>
<li><a href="#orgdf8e3c1"><b>string-area,current-free-address</b></a></li>
<li><a href="#org6fe77cc">the_last_link_in_assembly_code</a></li>
<li><a href="#org3f62ef">un_initialized_memory&#xa0;&#xa0;&#xa0;<span class="tag"><span class="linux">linux</span></span></a></li>
</ul>
</li>
</ul>
</div>
</div>

<div id="outline-container-orga27444d" class="outline-2">
<h2 id="orga27444d"><span class="done todo">todo</span> </h2>
<div class="outline-text-2" id="text-orga27444d">
</div><div id="outline-container-org45c1bbd" class="outline-3">
<h3 id="org45c1bbd">add length field into jo in assembly code&#xa0;&#xa0;&#xa0;<span class="tag"><span class="maybe">maybe</span></span></h3>
</div>

<div id="outline-container-org5bd126b" class="outline-3">
<h3 id="org5bd126b">memory&#xa0;&#xa0;&#xa0;<span class="tag"><span class="limit">limit</span></span></h3>
<div class="outline-text-3" id="text-org5bd126b">
<ul class="org-ul">
<li><p>need to protect the overloading of a variety of memories</p></li></ul>
</div>
</div>

<div id="outline-container-orgfc2a140" class="outline-3">
<h3 id="orgfc2a140">reading-stack&#xa0;&#xa0;&#xa0;<span class="tag"><span class="limit">limit</span></span></h3>
<div class="outline-text-3" id="text-orgfc2a140">
<ul class="org-ul">
<li><p>need to find a better way to protect reading-stack</p></li>
<li><p>now</p><p>"1 2 3 add add . jo" eval-string</p><p>will crush the interpreter</p></li></ul>
</div>
</div>

<div id="outline-container-org73bcf7b" class="outline-3">
<h3 id="org73bcf7b">div&#xa0;&#xa0;&#xa0;<span class="tag"><span class="bug">bug</span></span></h3>
<div class="outline-text-3" id="text-org73bcf7b">
<ul class="org-ul">
<li><p>div can not handle the following</p><p>-8 2 div .</p></li></ul>
</div>
</div>

<div id="outline-container-orgd8b135" class="outline-3">
<h3 id="orgd8b135">stack&#xa0;&#xa0;&#xa0;<span class="tag"><span class="limit">limit</span></span></h3>
<div class="outline-text-3" id="text-orgd8b135">
<ul class="org-ul">
<li><p>there are 64 positions below the all those stacks</p><p>when you are belowing-stack so much</p><p>bad things happen</p></li></ul>
</div>
</div>

<div id="outline-container-org1a6e822" class="outline-3">
<h3 id="org1a6e822">string-reverse!&#xa0;&#xa0;&#xa0;<span class="tag"><span class="bug">bug</span></span></h3>
<div class="outline-text-3" id="text-org1a6e822">
<ul class="org-ul">
<li><p>string-reverse! can not apply on empty-string</p></li></ul>
</div>
</div>
</div>


<div id="outline-container-org2a89c7f" class="outline-2">
<h2 id="org2a89c7f">prolog</h2>
<div class="outline-text-2" id="text-org2a89c7f">
</div><div id="outline-container-org64586e9" class="outline-3">
<h3 id="org64586e9"><span class="todo note">note</span> conditional preprocessing</h3>
<div class="outline-text-3" id="text-org64586e9">
<ul class="org-ul">
<li><p>flower bar-ket can not be nested in fasm's "match"</p><p>so</p><p><ol class="org-ol"></p><p><li>when defining macro conditionally</p><p>one should use "if eq" &amp; "finish if"</li></p><p><li>when doing "define" or "equ"</p><p>one should use "match { }"</li></ol></p></li></ul>
</div>
</div>

<div id="outline-container-orgf661c18" class="outline-3">
<h3 id="orgf661c18">platform configuration</h3>
<div class="outline-text-3" id="text-orgf661c18">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #FF8888;">;;;; before you compile the code</span>
<span style="color: #FF8888;">;;;; do not forget to choose your platform</span>
<span style="color: #FF8888;">;;;; in the following file</span>

<span style="color: #a6e22e;">include</span> <span style="color: #e6db74;">"platform-configuration.inc"</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org2277e96" class="outline-3">
<h3 id="org2277e96">misc</h3>
<div class="outline-text-3" id="text-org2277e96">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #FF8888;">;; in fasm, "dup" is a reserved word</span>
<span style="color: #f92672; font-weight: bold;">dup</span> <span style="color: #a6e22e;">equ</span> duplicate

<span style="color: #FF8888;">;; in fasm, "end" is a reserved word</span>
<span style="color: #f92672; font-weight: bold;">finish</span> <span style="color: #a6e22e;">equ</span> <span style="color: #f92672; font-weight: bold;">end</span>
<span style="color: #f92672; font-weight: bold;">end</span> <span style="color: #a6e22e;">equ</span> exit
</pre>
</div>
</div>
</div>


<div id="outline-container-orgcd521d6" class="outline-3">
<h3 id="orgcd521d6">cell_size&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></h3>
<div class="outline-text-3" id="text-orgcd521d6">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =64bit, machine {

cell_size = <span style="color: #ae81ff;">8</span> <span style="color: #FF8888;">;; (byte)</span>
<span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #a6e22e;">equ</span> <span style="color: #66d9ef; font-weight: bold;">dq</span>

}
</pre>
</div>
</div>
</div>

<div id="outline-container-orga1ff92b" class="outline-3">
<h3 id="orga1ff92b">cell_size&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></h3>
<div class="outline-text-3" id="text-orga1ff92b">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =32bit, machine {

cell_size = <span style="color: #ae81ff;">4</span> <span style="color: #FF8888;">;; (byte)</span>
<span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #a6e22e;">equ</span> <span style="color: #66d9ef; font-weight: bold;">dd</span>

<span style="color: #fd971f;">rax</span> <span style="color: #a6e22e;">equ</span> <span style="color: #fd971f;">eax</span>
<span style="color: #fd971f;">rbx</span> <span style="color: #a6e22e;">equ</span> <span style="color: #fd971f;">ebx</span>
<span style="color: #fd971f;">rcx</span> <span style="color: #a6e22e;">equ</span> <span style="color: #fd971f;">ecx</span>
<span style="color: #fd971f;">rdx</span> <span style="color: #a6e22e;">equ</span> <span style="color: #fd971f;">edx</span>

<span style="color: #fd971f;">rsp</span> <span style="color: #a6e22e;">equ</span> <span style="color: #fd971f;">esp</span>
<span style="color: #fd971f;">rbp</span> <span style="color: #a6e22e;">equ</span> <span style="color: #fd971f;">ebp</span>
<span style="color: #fd971f;">rsi</span> <span style="color: #a6e22e;">equ</span> <span style="color: #fd971f;">esi</span>
<span style="color: #fd971f;">rdi</span> <span style="color: #a6e22e;">equ</span> <span style="color: #fd971f;">edi</span>

<span style="color: #a6e22e;">syscall</span> <span style="color: #a6e22e;">equ</span> <span style="color: #a6e22e;">int</span> <span style="color: #ae81ff;">80h</span>

}
</pre>
</div>
</div>
</div>


<div id="outline-container-org8403cae" class="outline-3">
<h3 id="org8403cae">header&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span>&#xa0;<span class="linux">linux</span></span></h3>
<div class="outline-text-3" id="text-org8403cae">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =linux =64bit, platform machine {

<span style="color: #a6e22e;">define</span> linux64_sys_6_r8  <span style="color: #fd971f;">r8</span>
<span style="color: #a6e22e;">define</span> linux64_sys_5_r9  <span style="color: #fd971f;">r9</span>
<span style="color: #a6e22e;">define</span> linux64_sys_4_r10 <span style="color: #fd971f;">r10</span>
<span style="color: #a6e22e;">define</span> linux64_sys_3_rdx <span style="color: #fd971f;">rdx</span>
<span style="color: #a6e22e;">define</span> linux64_sys_2_rsi <span style="color: #fd971f;">rsi</span>
<span style="color: #a6e22e;">define</span> linux64_sys_1_rdi <span style="color: #fd971f;">rdi</span>
<span style="color: #a6e22e;">define</span> linux64_sys_n_rax <span style="color: #fd971f;">rax</span>

<span style="color: #a6e22e;">define</span> linux64_syscall_read   <span style="color: #ae81ff;">0</span>
<span style="color: #a6e22e;">define</span> linux64_syscall_write  <span style="color: #ae81ff;">1</span>
<span style="color: #a6e22e;">define</span> linux64_syscall_open   <span style="color: #ae81ff;">2</span>
<span style="color: #a6e22e;">define</span> linux64_syscall_close  <span style="color: #ae81ff;">3</span>
<span style="color: #a6e22e;">define</span> linux64_syscall_exit   <span style="color: #ae81ff;">60</span>
<span style="color: #FF8888;">;; about open &amp; read &amp; write</span>

}
</pre>
</div>
</div>
</div>

<div id="outline-container-orgff479c1" class="outline-3">
<h3 id="orgff479c1">format&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span>&#xa0;<span class="linux">linux</span></span></h3>
<div class="outline-text-3" id="text-orgff479c1">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =linux =64bit, platform machine {

<span style="color: #f92672; font-weight: bold;">format</span> ELF64 <span style="color: #f92672; font-weight: bold;">executable</span> <span style="color: #ae81ff;">3</span>

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org55a5623" class="outline-3">
<h3 id="org55a5623">entry&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span>&#xa0;<span class="linux">linux</span></span></h3>
<div class="outline-text-3" id="text-org55a5623">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =linux =64bit, platform machine {

<span style="color: #f92672; font-weight: bold;">entry</span> begin_to_interpret_threaded_code
<span style="color: #f92672; font-weight: bold;">segment</span> <span style="color: #f92672; font-weight: bold;">readable</span> <span style="color: #f92672; font-weight: bold;">executable</span> <span style="color: #f92672; font-weight: bold;">writeable</span>

}
</pre>
</div>
</div>
</div>


<div id="outline-container-org17a955b" class="outline-3">
<h3 id="org17a955b">header&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span>&#xa0;<span class="linux">linux</span></span></h3>
<div class="outline-text-3" id="text-org17a955b">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =linux =32bit, platform machine {

<span style="color: #a6e22e;">define</span> linux32_sys_6_ebp <span style="color: #fd971f;">ebp</span>
<span style="color: #a6e22e;">define</span> linux32_sys_5_edi <span style="color: #fd971f;">edi</span>
<span style="color: #a6e22e;">define</span> linux32_sys_4_esi <span style="color: #fd971f;">esi</span>
<span style="color: #a6e22e;">define</span> linux32_sys_3_edx <span style="color: #fd971f;">edx</span>
<span style="color: #a6e22e;">define</span> linux32_sys_2_ecx <span style="color: #fd971f;">ecx</span>
<span style="color: #a6e22e;">define</span> linux32_sys_1_ebx <span style="color: #fd971f;">ebx</span>
<span style="color: #a6e22e;">define</span> linux32_sys_n_eax <span style="color: #fd971f;">eax</span>

<span style="color: #a6e22e;">define</span> linux32_syscall_exit    <span style="color: #ae81ff;">1</span>
<span style="color: #a6e22e;">define</span> linux32_syscall_read    <span style="color: #ae81ff;">3</span>
<span style="color: #a6e22e;">define</span> linux32_syscall_write   <span style="color: #ae81ff;">4</span>
<span style="color: #a6e22e;">define</span> linux32_syscall_open    <span style="color: #ae81ff;">5</span>
<span style="color: #a6e22e;">define</span> linux32_syscall_close   <span style="color: #ae81ff;">6</span>

}
</pre>
</div>
</div>
</div>

<div id="outline-container-orge8cac7c" class="outline-3">
<h3 id="orge8cac7c">format&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span>&#xa0;<span class="linux">linux</span></span></h3>
<div class="outline-text-3" id="text-orge8cac7c">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =linux =32bit, platform machine {

<span style="color: #f92672; font-weight: bold;">format</span> ELF <span style="color: #f92672; font-weight: bold;">executable</span> <span style="color: #ae81ff;">3</span>

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org875ea93" class="outline-3">
<h3 id="org875ea93">entry&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span>&#xa0;<span class="linux">linux</span></span></h3>
<div class="outline-text-3" id="text-org875ea93">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =linux =32bit, platform machine {

<span style="color: #f92672; font-weight: bold;">entry</span> begin_to_interpret_threaded_code
<span style="color: #f92672; font-weight: bold;">segment</span> <span style="color: #f92672; font-weight: bold;">readable</span> <span style="color: #f92672; font-weight: bold;">executable</span> <span style="color: #f92672; font-weight: bold;">writeable</span>

}
</pre>
</div>
</div>
</div>


<div id="outline-container-org897c344" class="outline-3">
<h3 id="org897c344">memory allocation in un_initialized_memory</h3>
<div class="outline-text-3" id="text-org897c344">
<ul class="org-ul">
<li><p>implemented as a memory map</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">current_free_address$un_initialized_memory = address$un_initialized_memory

<span style="color: #f92672; font-weight: bold;">labeling</span>  <span style="color: #a6e22e;">equ</span> = current_free_address$un_initialized_memory
<span style="color: #66d9ef; font-weight: bold;">preserve</span>  <span style="color: #a6e22e;">equ</span> current_free_address$un_initialized_memory = current_free_address$un_initialized_memory +
</pre>
</div>
</div>
</div>
</div>



<div id="outline-container-org96d9b81" class="outline-2">
<h2 id="org96d9b81">argument-stack</h2>
<div class="outline-text-2" id="text-org96d9b81">
</div><div id="outline-container-orgd7c52ca" class="outline-3">
<h3 id="orgd7c52ca"><span class="todo note">note</span> stack</h3>
<div class="outline-text-3" id="text-orgd7c52ca">
<ul class="org-ul">
<li><p>when doing "push"</p><p>a stack-pointer moves to lower address</p></li>
<li><p>note that another style is that</p><p>when doing "push"</p><p>a stack-pointer moves to higher address</p></li>
<li><p>the stack-pointer</p><p>always stores the address of current-free-address of the stack</p></li>
<li><p>note that another style is that</p><p>under the stack-pointer</p><p>there always stores the value of the-top-of-the-stack</p></li></ul>
</div>
</div>

<div id="outline-container-org84d762" class="outline-3">
<h3 id="org84d762">memory allocation</h3>
<div class="outline-text-3" id="text-org84d762">
<ul class="org-ul">
<li><p>for we do not build border-check</p><p>into the interface of pop and push</p><p>we allocation some memory below the stacks</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">size$argument_stack = <span style="color: #ae81ff;">1024</span> * <span style="color: #ae81ff;">1024</span> * cell_size

   <span style="color: #66d9ef; font-weight: bold;">preserve</span> <span style="color: #ae81ff;">64</span> * cell_size
address$argument_stack <span style="color: #f92672; font-weight: bold;">labeling</span>
   <span style="color: #66d9ef; font-weight: bold;">preserve</span> size$argument_stack
</pre>
</div>
</div>
</div>

<div id="outline-container-orgf0b6cf1" class="outline-3">
<h3 id="orgf0b6cf1">pointer&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></h3>
<div class="outline-text-3" id="text-orgf0b6cf1">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =64bit, machine {

<span style="color: #FF8888;">;; if you want to extend cicada in assembly</span>
<span style="color: #FF8888;">;; the following registers must NOT be used</span>

<span style="color: #a6e22e;">define</span> pointer$argument_stack <span style="color: #fd971f;">r15</span>

}
</pre>
</div>
</div>
</div>

<div id="outline-container-orga155ead" class="outline-3">
<h3 id="orga155ead">push &amp; pop&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></h3>
<div class="outline-text-3" id="text-orga155ead">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =64bit, machine {

<span style="color: #a6e22e;">macro</span> <span style="color: #a6e22e;">push_argument_stack</span> register \{
   <span style="color: #a6e22e;">mov</span> [pointer$argument_stack], register
   <span style="color: #a6e22e;">add</span> pointer$argument_stack, cell_size
\}

<span style="color: #a6e22e;">macro</span> <span style="color: #a6e22e;">pop_argument_stack</span> register \{
   <span style="color: #a6e22e;">sub</span> pointer$argument_stack, cell_size
   <span style="color: #a6e22e;">mov</span> register, [pointer$argument_stack]
\}

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org1a87a91" class="outline-3">
<h3 id="org1a87a91">pointer&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></h3>
<div class="outline-text-3" id="text-org1a87a91">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =32bit, machine {

<span style="color: #a6e22e;">pointer$argument_stack</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> address$argument_stack

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org98133d5" class="outline-3">
<h3 id="org98133d5">push &amp; pop&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></h3>
<div class="outline-text-3" id="text-org98133d5">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =32bit, machine {

<span style="color: #a6e22e;">macro</span> <span style="color: #a6e22e;">push_argument_stack</span> register \{
   <span style="color: #f92672; font-weight: bold;">if</span> register <span style="color: #a6e22e;">in</span> &lt;eax&gt;
   <span style="color: #a6e22e;">push</span> <span style="color: #fd971f;">ebx</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">ebx</span>, [pointer$argument_stack]
   <span style="color: #a6e22e;">mov</span> [<span style="color: #fd971f;">ebx</span>], register
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">ebx</span>, cell_size
   <span style="color: #a6e22e;">mov</span> [pointer$argument_stack], <span style="color: #fd971f;">ebx</span>
   <span style="color: #a6e22e;">pop</span> <span style="color: #fd971f;">ebx</span>
   <span style="color: #f92672; font-weight: bold;">else</span>
   <span style="color: #a6e22e;">push</span> <span style="color: #fd971f;">eax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">eax</span>, [pointer$argument_stack]
   <span style="color: #a6e22e;">mov</span> [<span style="color: #fd971f;">eax</span>], register
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">eax</span>, cell_size
   <span style="color: #a6e22e;">mov</span> [pointer$argument_stack], <span style="color: #fd971f;">eax</span>
   <span style="color: #a6e22e;">pop</span> <span style="color: #fd971f;">eax</span>
   <span style="color: #f92672; font-weight: bold;">finish</span> <span style="color: #f92672; font-weight: bold;">if</span>
\}

<span style="color: #a6e22e;">macro</span> <span style="color: #a6e22e;">pop_argument_stack</span> register \{
   <span style="color: #f92672; font-weight: bold;">if</span> register <span style="color: #a6e22e;">in</span> &lt;eax&gt;
   <span style="color: #a6e22e;">push</span> <span style="color: #fd971f;">ebx</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">ebx</span>, [pointer$argument_stack]
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">ebx</span>, cell_size
   <span style="color: #a6e22e;">mov</span> register, [<span style="color: #fd971f;">ebx</span>]
   <span style="color: #a6e22e;">mov</span> [pointer$argument_stack], <span style="color: #fd971f;">ebx</span>
   <span style="color: #a6e22e;">pop</span> <span style="color: #fd971f;">ebx</span>
   <span style="color: #f92672; font-weight: bold;">else</span>
   <span style="color: #a6e22e;">push</span> <span style="color: #fd971f;">eax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">eax</span>, [pointer$argument_stack]
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">eax</span>, cell_size
   <span style="color: #a6e22e;">mov</span> register, [<span style="color: #fd971f;">eax</span>]
   <span style="color: #a6e22e;">mov</span> [pointer$argument_stack], <span style="color: #fd971f;">eax</span>
   <span style="color: #a6e22e;">pop</span> <span style="color: #fd971f;">eax</span>
   <span style="color: #f92672; font-weight: bold;">finish</span> <span style="color: #f92672; font-weight: bold;">if</span>
\}

}
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-org64020d4" class="outline-2">
<h2 id="org64020d4">return-stack</h2>
<div class="outline-text-2" id="text-org64020d4">
</div><div id="outline-container-org7ee867e" class="outline-3">
<h3 id="org7ee867e"><span class="todo _">記</span> </h3>
<div class="outline-text-3" id="text-org7ee867e">
<ul class="org-ul">
<li><p>jo 的詮釋者</p><p>決定了 如何入這個棧</p></li>
<li><p>結尾詞</p><p>決定了 如何出這個棧</p></li></ul>
</div>
</div>

<div id="outline-container-orgbfad70" class="outline-3">
<h3 id="orgbfad70">memory allocation</h3>
<div class="outline-text-3" id="text-orgbfad70">
<div class="org-src-container">

<pre class="src src-fasm">size$return_stack = <span style="color: #ae81ff;">1024</span> * <span style="color: #ae81ff;">1024</span> * cell_size

   <span style="color: #66d9ef; font-weight: bold;">preserve</span> <span style="color: #ae81ff;">64</span> * cell_size
address$return_stack <span style="color: #f92672; font-weight: bold;">labeling</span>
   <span style="color: #66d9ef; font-weight: bold;">preserve</span> size$return_stack
</pre>
</div>
</div>
</div>

<div id="outline-container-org2898d45" class="outline-3">
<h3 id="org2898d45">pointer&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></h3>
<div class="outline-text-3" id="text-org2898d45">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =64bit, machine {

<span style="color: #FF8888;">;; if you want to extend cicada in assembly</span>
<span style="color: #FF8888;">;; the following registers must NOT be used</span>

<span style="color: #a6e22e;">define</span> pointer$return_stack <span style="color: #fd971f;">r14</span>

}
</pre>
</div>
</div>
</div>

<div id="outline-container-orga9edac5" class="outline-3">
<h3 id="orga9edac5">push &amp; pop&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></h3>
<div class="outline-text-3" id="text-orga9edac5">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =64bit, machine {

<span style="color: #a6e22e;">macro</span> <span style="color: #a6e22e;">push_return_stack</span> register \{
   <span style="color: #a6e22e;">mov</span> [pointer$return_stack], register
   <span style="color: #a6e22e;">add</span> pointer$return_stack, cell_size
\}

<span style="color: #a6e22e;">macro</span> <span style="color: #a6e22e;">pop_return_stack</span> register \{
   <span style="color: #a6e22e;">sub</span> pointer$return_stack, cell_size
   <span style="color: #a6e22e;">mov</span> register, [pointer$return_stack]
\}

}
</pre>
</div>
</div>
</div>

<div id="outline-container-orge5102f3" class="outline-3">
<h3 id="orge5102f3">pointer&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></h3>
<div class="outline-text-3" id="text-orge5102f3">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =32bit, machine {

<span style="color: #a6e22e;">pointer$return_stack</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> address$return_stack

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org4477a8d" class="outline-3">
<h3 id="org4477a8d">push &amp; pop&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></h3>
<div class="outline-text-3" id="text-org4477a8d">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =32bit, machine {

<span style="color: #a6e22e;">macro</span> <span style="color: #a6e22e;">push_return_stack</span> register \{
   <span style="color: #f92672; font-weight: bold;">if</span> register <span style="color: #a6e22e;">in</span> &lt;eax&gt;
   <span style="color: #a6e22e;">push</span> <span style="color: #fd971f;">ebx</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">ebx</span>, [pointer$return_stack]
   <span style="color: #a6e22e;">mov</span> [<span style="color: #fd971f;">ebx</span>], register
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">ebx</span>, cell_size
   <span style="color: #a6e22e;">mov</span> [pointer$return_stack], <span style="color: #fd971f;">ebx</span>
   <span style="color: #a6e22e;">pop</span> <span style="color: #fd971f;">ebx</span>
   <span style="color: #f92672; font-weight: bold;">else</span>
   <span style="color: #a6e22e;">push</span> <span style="color: #fd971f;">eax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">eax</span>, [pointer$return_stack]
   <span style="color: #a6e22e;">mov</span> [<span style="color: #fd971f;">eax</span>], register
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">eax</span>, cell_size
   <span style="color: #a6e22e;">mov</span> [pointer$return_stack], <span style="color: #fd971f;">eax</span>
   <span style="color: #a6e22e;">pop</span> <span style="color: #fd971f;">eax</span>
   <span style="color: #f92672; font-weight: bold;">finish</span> <span style="color: #f92672; font-weight: bold;">if</span>
\}

<span style="color: #a6e22e;">macro</span> <span style="color: #a6e22e;">pop_return_stack</span> register \{
   <span style="color: #f92672; font-weight: bold;">if</span> register <span style="color: #a6e22e;">in</span> &lt;eax&gt;
   <span style="color: #a6e22e;">push</span> <span style="color: #fd971f;">ebx</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">ebx</span>, [pointer$return_stack]
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">ebx</span>, cell_size
   <span style="color: #a6e22e;">mov</span> register, [<span style="color: #fd971f;">ebx</span>]
   <span style="color: #a6e22e;">mov</span> [pointer$return_stack], <span style="color: #fd971f;">ebx</span>
   <span style="color: #a6e22e;">pop</span> <span style="color: #fd971f;">ebx</span>
   <span style="color: #f92672; font-weight: bold;">else</span>
   <span style="color: #a6e22e;">push</span> <span style="color: #fd971f;">eax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">eax</span>, [pointer$return_stack]
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">eax</span>, cell_size
   <span style="color: #a6e22e;">mov</span> register, [<span style="color: #fd971f;">eax</span>]
   <span style="color: #a6e22e;">mov</span> [pointer$return_stack], <span style="color: #fd971f;">eax</span>
   <span style="color: #a6e22e;">pop</span> <span style="color: #fd971f;">eax</span>
   <span style="color: #f92672; font-weight: bold;">finish</span> <span style="color: #f92672; font-weight: bold;">if</span>
\}

}
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-org4b4d0f0" class="outline-2">
<h2 id="org4b4d0f0">next</h2>
<div class="outline-text-2" id="text-org4b4d0f0">
</div><div id="outline-container-orgd6112ae" class="outline-3">
<h3 id="orgd6112ae">macro next</h3>
<div class="outline-text-3" id="text-orgd6112ae">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =64bit, machine {

<span style="color: #a6e22e;">macro</span> <span style="color: #a6e22e;">next</span> \{
   pop_return_stack <span style="color: #fd971f;">rbx</span>
     <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rbx</span>]
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rbx</span>, cell_size
   push_return_stack <span style="color: #fd971f;">rbx</span>
     <span style="color: #a6e22e;">jmp</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [<span style="color: #fd971f;">rax</span>]
\}

}


<span style="color: #a6e22e;">match</span> =32bit, machine {

<span style="color: #a6e22e;">macro</span> <span style="color: #a6e22e;">next</span> \{
   pop_return_stack <span style="color: #fd971f;">rbx</span>
     <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rbx</span>]
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rbx</span>, cell_size
   push_return_stack <span style="color: #fd971f;">rbx</span>
     <span style="color: #a6e22e;">jmp</span> <span style="color: #66d9ef; font-weight: bold;">dword</span> [<span style="color: #fd971f;">rax</span>]
\}

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org60e653a" class="outline-3">
<h3 id="org60e653a"><span class="todo note">note</span> play with jo &amp; jojo</h3>
<div class="outline-text-3" id="text-org60e653a">
<ol class="org-ol">
<li>at the beginning
<ul class="org-ul">
<li><p>argument-stack</p><p>&lt;&lt; 2 &gt;&gt;</p></li>
<li><p><p></p><p>return-stack</p><p></p></p><p><div class="org-src-container"></p><p></p><p><pre class="src src-return-stack"><span style="color: #ae81ff; font-weight: bold;">-</span> <span style="color: #dc322f; font-weight: bold;">[</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span> <span style="color: #fd971f; font-weight: bold;">(square)</span> <span style="color: #dc322f; font-weight: bold;">]</span></p><p>          <span style="color: #ef5939; font-weight: bold;">(square)</span></p><p>          <span style="color: #00ffff; font-weight: bold;">(end)</span></p><p></pre></p><p></div></p></li></ul></li>
<li>next
<ul class="org-ul">
<li><p>argument-stack</p><p>&lt;&lt; 2 &gt;&gt;</p></li>
<li><p><p></p><p>return-stack</p><p></p></p><p><div class="org-src-container"></p><p></p><p><pre class="src src-return-stack">          <span style="color: #ef5939; font-weight: bold;">(square)</span></p><p><span style="color: #ae81ff; font-weight: bold;">-</span> <span style="color: #dc322f; font-weight: bold;">[</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span> <span style="color: #fd971f; font-weight: bold;">(square)</span> <span style="color: #dc322f; font-weight: bold;">]</span> <span style="color: #ae81ff; font-weight: bold;">-</span> <span style="color: #dc322f; font-weight: bold;">[</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span> <span style="color: #fd971f; font-weight: bold;">(dup)</span> <span style="color: #dc322f; font-weight: bold;">]</span></p><p>          <span style="color: #00ffff; font-weight: bold;">(end)</span>                <span style="color: #ef5939; font-weight: bold;">(mul)</span></p><p>                               <span style="color: #00ffff; font-weight: bold;">(end)</span></p><p></pre></p><p></div></p></li></ul></li>
<li>next
<ul class="org-ul">
<li><p>argument-stack</p><p>&lt;&lt; 2, 2 &gt;&gt;</p></li>
<li><p><p></p><p>return-stack</p><p></p></p><p><div class="org-src-container"></p><p></p><p><pre class="src src-return-stack">          <span style="color: #ef5939; font-weight: bold;">(square)</span>             <span style="color: #ef5939; font-weight: bold;">(dup)</span></p><p><span style="color: #ae81ff; font-weight: bold;">-</span> <span style="color: #dc322f; font-weight: bold;">[</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span> <span style="color: #fd971f; font-weight: bold;">(square)</span> <span style="color: #dc322f; font-weight: bold;">]</span> <span style="color: #ae81ff; font-weight: bold;">-</span> <span style="color: #dc322f; font-weight: bold;">[</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span> <span style="color: #fd971f; font-weight: bold;">(mul)</span> <span style="color: #dc322f; font-weight: bold;">]</span></p><p>          <span style="color: #00ffff; font-weight: bold;">(end)</span>                <span style="color: #00ffff; font-weight: bold;">(end)</span></p><p></pre></p><p></div></p></li></ul></li>
<li>next
<ul class="org-ul">
<li><p>argument-stack &lt;&lt; 4 &gt;&gt;</p></li>
<li><p><p></p><p>return-stack</p><p></p></p><p><div class="org-src-container"></p><p></p><p><pre class="src src-return-stack">                               <span style="color: #ef5939; font-weight: bold;">(dup)</span></p><p>          <span style="color: #ef5939; font-weight: bold;">(square)</span>             <span style="color: #ef5939; font-weight: bold;">(mul)</span></p><p><span style="color: #ae81ff; font-weight: bold;">-</span> <span style="color: #dc322f; font-weight: bold;">[</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span> <span style="color: #fd971f; font-weight: bold;">(square)</span> <span style="color: #dc322f; font-weight: bold;">]</span> <span style="color: #ae81ff; font-weight: bold;">-</span> <span style="color: #dc322f; font-weight: bold;">[</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span> <span style="color: #00ffff; font-weight: bold;">(end)</span> <span style="color: #dc322f; font-weight: bold;">]</span></p><p>          <span style="color: #00ffff; font-weight: bold;">(end)</span></p><p></pre></p><p></div></p></li></ul></li>
<li>next
<ul class="org-ul">
<li><p>argument-stack &lt;&lt; 4 &gt;&gt;</p></li>
<li><p><p></p><p>return-stack</p><p></p></p><p><div class="org-src-container"></p><p></p><p><pre class="src src-return-stack">          <span style="color: #ef5939; font-weight: bold;">(square)</span></p><p>          <span style="color: #ef5939; font-weight: bold;">(square)</span></p><p><span style="color: #ae81ff; font-weight: bold;">-</span> <span style="color: #dc322f; font-weight: bold;">[</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span> <span style="color: #00ffff; font-weight: bold;">(end)</span> <span style="color: #dc322f; font-weight: bold;">]</span> <span style="color: #ae81ff; font-weight: bold;">-</span> <span style="color: #dc322f; font-weight: bold;">[</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span> <span style="color: #fd971f; font-weight: bold;">(dup)</span> <span style="color: #dc322f; font-weight: bold;">]</span></p><p>                            <span style="color: #ef5939; font-weight: bold;">(mul)</span></p><p>                            <span style="color: #00ffff; font-weight: bold;">(end)</span></p><p></pre></p><p></div></p></li></ul></li>
<li>next
<ul class="org-ul">
<li><p>argument-stack</p><p>&lt;&lt; 4, 4 &gt;&gt;</p></li>
<li><p><p></p><p>return-stack</p><p></p></p><p><div class="org-src-container"></p><p></p><p><pre class="src src-return-stack">          <span style="color: #ef5939; font-weight: bold;">(square)</span></p><p>          <span style="color: #ef5939; font-weight: bold;">(square)</span>          <span style="color: #ef5939; font-weight: bold;">(dup)</span></p><p><span style="color: #ae81ff; font-weight: bold;">-</span> <span style="color: #dc322f; font-weight: bold;">[</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span> <span style="color: #00ffff; font-weight: bold;">(end)</span> <span style="color: #dc322f; font-weight: bold;">]</span> <span style="color: #ae81ff; font-weight: bold;">-</span> <span style="color: #dc322f; font-weight: bold;">[</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span> <span style="color: #fd971f; font-weight: bold;">(mul)</span> <span style="color: #dc322f; font-weight: bold;">]</span></p><p>                            <span style="color: #00ffff; font-weight: bold;">(end)</span></p><p></pre></p><p></div></p></li></ul></li>
<li>next
<ul class="org-ul">
<li><p>argument-stack</p><p>&lt;&lt; 16 &gt;&gt;</p></li>
<li><p><p></p><p>return-stack</p><p></p></p><p><div class="org-src-container"></p><p></p><p><pre class="src src-return-stack">          <span style="color: #ef5939; font-weight: bold;">(square)</span>          <span style="color: #ef5939; font-weight: bold;">(dup)</span></p><p>          <span style="color: #ef5939; font-weight: bold;">(square)</span>          <span style="color: #ef5939; font-weight: bold;">(mul)</span></p><p><span style="color: #ae81ff; font-weight: bold;">-</span> <span style="color: #dc322f; font-weight: bold;">[</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span> <span style="color: #00ffff; font-weight: bold;">(end)</span> <span style="color: #dc322f; font-weight: bold;">]</span> <span style="color: #ae81ff; font-weight: bold;">-</span> <span style="color: #dc322f; font-weight: bold;">[</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span> <span style="color: #00ffff; font-weight: bold;">(end)</span> <span style="color: #dc322f; font-weight: bold;">]</span></p><p></pre></p><p></div></p></li></ul></li>
<li>next
<ul class="org-ul">
<li><p>argument-stack</p><p>&lt;&lt; 16 &gt;&gt;</p></li>
<li><p><p></p><p>return-stack</p><p></p></p><p><div class="org-src-container"></p><p></p><p><pre class="src src-return-stack">          <span style="color: #ef5939; font-weight: bold;">(square)</span></p><p>          <span style="color: #ef5939; font-weight: bold;">(square)</span></p><p><span style="color: #ae81ff; font-weight: bold;">-</span> <span style="color: #dc322f; font-weight: bold;">[</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span> <span style="color: #00ffff; font-weight: bold;">(end)</span> <span style="color: #dc322f; font-weight: bold;">]</span></p><p></pre></p><p></div></p></li></ul></li>
<li>next
<ul class="org-ul">
<li><p>argument-stack</p><p>&lt;&lt; 16 &gt;&gt;</p></li>
<li><p><p></p><p>return-stack</p><p></p></p><p><div class="org-src-container"></p><p></p><p><pre class="src src-return-stack"><span style="color: #ae81ff; font-weight: bold;">-</span> [  ]</p><p></pre></p><p></div></p></li></ul></li>
<li>it is really simple
^-^
is it not ?</li></ol>
</div>
</div>
</div>

<div id="outline-container-org7daaf22" class="outline-2">
<h2 id="org7daaf22">function-jo</h2>
<div class="outline-text-2" id="text-org7daaf22">
</div><div id="outline-container-orgdbbb7d2" class="outline-3">
<h3 id="orgdbbb7d2"><span class="todo note">note</span> jo</h3>
<div class="outline-text-3" id="text-orgdbbb7d2">
<ul class="org-ul">
<li><p><p></p><p>jo as data-structure</p><p></p></p><p><table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"></p><p></p><p></p><p><colgroup></p><p><col  class="org-left" /></p><p></p><p><col  class="org-left" /></p><p></colgroup></p><p><tbody></p><p><tr></p><p><td class="org-left">&#xa0;</td></p><p><td class="org-left">length</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">jo</td></p><p><td class="org-left">explainer</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">&#xa0;</td></p><p><td class="org-left">body</td></p><p></tr></p><p></tbody></p><p></table></p></li>
<li><p>the body for</p><p><ul class="org-ul"></p><p><li><p>primitive-function-jo</p><p>assembly code</p></li></p><p><li><p>function-jo</p><p>jojo</p></li></p><p><li><p>variable-jo</p><p>value-list</p></li></ul></p></li></ul>
</div>
</div>

<div id="outline-container-orgd5f5ecb" class="outline-3">
<h3 id="orgd5f5ecb">offset of jo</h3>
<div class="outline-text-3" id="text-orgd5f5ecb">
<div class="org-src-container">

<pre class="src src-fasm">offset__jo$other          = - (cell_size * <span style="color: #ae81ff;">2</span>)
offset__jo$length         = - (cell_size * <span style="color: #ae81ff;">1</span>)
offset__jo$body           = (cell_size * <span style="color: #ae81ff;">1</span>)
</pre>
</div>
</div>
</div>

<div id="outline-container-org8851c88" class="outline-3">
<h3 id="org8851c88"><span class="todo note">note</span> link</h3>
<div class="outline-text-3" id="text-org8851c88">
<ul class="org-ul">
<li><p><p></p><p>link as data-structure</p><p></p></p><p><table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"></p><p></p><p></p><p><colgroup></p><p><col  class="org-left" /></p><p></p><p><col  class="org-left" /></p><p></colgroup></p><p><thead></p><p><tr></p><p><th scope="col" class="org-left">link</th></p><p><th scope="col" class="org-left">link</th></p><p></tr></p><p></thead></p><p><tbody></p><p><tr></p><p><td class="org-left">&#xa0;</td></p><p><td class="org-left">jo</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">&#xa0;</td></p><p><td class="org-left">string-address</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">&#xa0;</td></p><p><td class="org-left">string-length</td></p><p></tr></p><p></tbody></p><p></table></p></li>
<li><p>if the link field of a link is 0</p><p>the link is the last-link</p></li></ul>
</div>
</div>

<div id="outline-container-org994cbb9" class="outline-3">
<h3 id="org994cbb9">offset of link</h3>
<div class="outline-text-3" id="text-org994cbb9">
<div class="org-src-container">

<pre class="src src-fasm">offset__link$jo             = (cell_size * <span style="color: #ae81ff;">1</span>)
offset__link$string_address = (cell_size * <span style="color: #ae81ff;">2</span>)
offset__link$string_length  = (cell_size * <span style="color: #ae81ff;">3</span>)
</pre>
</div>
</div>
</div>

<div id="outline-container-org245ef4" class="outline-3">
<h3 id="org245ef4">null link</h3>
<div class="outline-text-3" id="text-org245ef4">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #FF8888;">;; initial link to point to 0 (as null)</span>
link = <span style="color: #ae81ff;">0</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org32f474e" class="outline-3">
<h3 id="org32f474e"><b>string-area</b></h3>
<div class="outline-text-3" id="text-org32f474e">
</div><div id="outline-container-orgacfb46" class="outline-4">
<h4 id="orgacfb46">memory allocation</h4>
<div class="outline-text-4" id="text-orgacfb46">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">address$string_area</span>:
   <span style="color: #f92672; font-weight: bold;">times</span> <span style="color: #ae81ff;">64</span> * <span style="color: #ae81ff;">1024</span> <span style="color: #66d9ef; font-weight: bold;">db</span> <span style="color: #ae81ff;">0</span>

<span style="color: #a6e22e;">address$core_file</span>:
   <span style="color: #f92672; font-weight: bold;">file</span> <span style="color: #e6db74;">"core/core.cn"</span>
<span style="color: #a6e22e;">end$core_file</span>:

<span style="color: #a6e22e;">end$string_area</span>:

current_free_address$string_area = address$string_area
</pre>
</div>
</div>
</div>

<div id="outline-container-org2837e17" class="outline-4">
<h4 id="org2837e17">ASSEMBLY__length_string</h4>
<div class="outline-text-4" id="text-org2837e17">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">macro</span> <span style="color: #a6e22e;">ASSEMBLY__length_string</span> string {

<span style="color: #f92672; font-weight: bold;">virtual</span> <span style="color: #f92672; font-weight: bold;">at</span> <span style="color: #ae81ff;">0</span>
<span style="color: #a6e22e;">.start$string</span>:
   <span style="color: #66d9ef; font-weight: bold;">db</span> string
<span style="color: #a6e22e;">.end$string</span>:
   <span style="color: #66d9ef; font-weight: bold;">dw</span> (.end$string - .start$string)
   <span style="color: #f92672; font-weight: bold;">load</span> .length <span style="color: #66d9ef; font-weight: bold;">word</span> <span style="color: #f92672; font-weight: bold;">from</span> (.end$string)
<span style="color: #f92672; font-weight: bold;">finish</span> <span style="color: #f92672; font-weight: bold;">virtual</span>

}
</pre>
</div>
</div>
</div>

<div id="outline-container-orgaaef7d9" class="outline-4">
<h4 id="orgaaef7d9">ASSEMBLY__make_string</h4>
<div class="outline-text-4" id="text-orgaaef7d9">
<ul class="org-ul">
<li><p>note that</p><p>the following is using local label</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">macro</span> <span style="color: #a6e22e;">ASSEMBLY__make_string</span> string {

<span style="color: #f92672; font-weight: bold;">repeat</span> .length
   <span style="color: #f92672; font-weight: bold;">virtual</span> <span style="color: #f92672; font-weight: bold;">at</span> <span style="color: #ae81ff;">0</span>
      <span style="color: #66d9ef; font-weight: bold;">db</span> string
      <span style="color: #f92672; font-weight: bold;">load</span> .char <span style="color: #66d9ef; font-weight: bold;">byte</span> <span style="color: #f92672; font-weight: bold;">from</span> (% - <span style="color: #ae81ff;">1</span>)
   <span style="color: #f92672; font-weight: bold;">finish</span> <span style="color: #f92672; font-weight: bold;">virtual</span>
   <span style="color: #f92672; font-weight: bold;">store</span> <span style="color: #66d9ef; font-weight: bold;">byte</span> .char <span style="color: #f92672; font-weight: bold;">at</span> (current_free_address$string_area)
   current_free_address$string_area = current_free_address$string_area + <span style="color: #ae81ff;">1</span>
<span style="color: #f92672; font-weight: bold;">finish</span> <span style="color: #f92672; font-weight: bold;">repeat</span>
   <span style="color: #f92672; font-weight: bold;">store</span> <span style="color: #66d9ef; font-weight: bold;">byte</span> <span style="color: #ae81ff;">0</span> <span style="color: #f92672; font-weight: bold;">at</span> (current_free_address$string_area)
   current_free_address$string_area = current_free_address$string_area + <span style="color: #ae81ff;">1</span>
}
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-org16111ff" class="outline-3">
<h3 id="org16111ff"><span class="todo note">note</span> </h3>
<div class="outline-text-3" id="text-org16111ff">
<ul class="org-ul">
<li><p>note that</p><p>after a "next" "jmp" to a explainer</p><p>the "rax" stores the value of the jo to be explained</p><p>so</p><p>"rax" is used as an inexplicit argument</p><p>of the following functions</p></li>
<li><p>explain$function is used as jojo-head</p><p>and explains the meaning of the jojo as function</p></li>
<li><p>a jojo-head identifies one type of jo</p></li></ul>
</div>
</div>

<div id="outline-container-orgf3dcfe5" class="outline-3">
<h3 id="orgf3dcfe5">define_function</h3>
<div class="outline-text-3" id="text-orgf3dcfe5">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">macro</span> <span style="color: #a6e22e;">define_function</span> string, <span style="color: #a6e22e;">jo</span> {

link__#<span style="color: #a6e22e;">jo</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> link
   link = link__#<span style="color: #a6e22e;">jo</span>

   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #a6e22e;">jo</span>

   ASSEMBLY__length_string string
   .address = current_free_address$string_area
   <span style="color: #66d9ef; font-weight: bold;">xx</span> .address
   <span style="color: #66d9ef; font-weight: bold;">xx</span> .length
   ASSEMBLY__make_string string


   <span style="color: #FF8888;">;; xx (end__#jo - jo)/cell_size</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #ae81ff;">0</span>

<span style="color: #a6e22e;">jo</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> explain$function

   <span style="color: #FF8888;">;; here follows a jojo as function-body</span>

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org2f493c5" class="outline-3">
<h3 id="org2f493c5">explain$function</h3>
<div class="outline-text-3" id="text-org2f493c5">
<ul class="org-ul">
<li><p>push the jojo of a jo to return-stack</p></li>
<li><p>a jojo can not be of size 0</p></li>
<li><p>use rax as an argument</p><p>which stores a jo</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =64bit, machine {

<span style="color: #a6e22e;">explain$function</span>:
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, pointer$return_stack
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">rbx</span>, address$return_stack
   <span style="color: #a6e22e;">test</span> <span style="color: #fd971f;">rbx</span>, unit__return_point
   <span style="color: #a6e22e;">jz</span> .return_stack_even

   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [V__local_memory_odd__current_free_address + cell_size]
   push_return_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [V__local_memory_even__current_free_address + cell_size]
   push_return_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [local_variable$current_free_address]
   push_return_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rax</span>, cell_size
   push_return_stack <span style="color: #fd971f;">rax</span>
   next

<span style="color: #a6e22e;">.return_stack_even</span>:
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [V__local_memory_even__current_free_address + cell_size]
   push_return_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [V__local_memory_odd__current_free_address + cell_size]
   push_return_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [local_variable$current_free_address]
   push_return_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rax</span>, cell_size
   push_return_stack <span style="color: #fd971f;">rax</span>
   next

}

<span style="color: #a6e22e;">match</span> =32bit, machine {

<span style="color: #a6e22e;">explain$function</span>:
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [pointer$return_stack]
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">rbx</span>, address$return_stack
   <span style="color: #a6e22e;">test</span> <span style="color: #fd971f;">rbx</span>, unit__return_point
   <span style="color: #a6e22e;">jz</span> .return_stack_even

   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [V__local_memory_odd__current_free_address + cell_size]
   push_return_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [V__local_memory_even__current_free_address + cell_size]
   push_return_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [local_variable$current_free_address]
   push_return_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rax</span>, cell_size
   push_return_stack <span style="color: #fd971f;">rax</span>
   next

<span style="color: #a6e22e;">.return_stack_even</span>:
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [V__local_memory_even__current_free_address + cell_size]
   push_return_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [V__local_memory_odd__current_free_address + cell_size]
   push_return_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [local_variable$current_free_address]
   push_return_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rax</span>, cell_size
   push_return_stack <span style="color: #fd971f;">rax</span>
   next

}
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-org65852ef" class="outline-2">
<h2 id="org65852ef">primitive-function-jo</h2>
<div class="outline-text-2" id="text-org65852ef">
</div><div id="outline-container-org24601b6" class="outline-3">
<h3 id="org24601b6"><span class="todo note">note</span> </h3>
<div class="outline-text-3" id="text-org24601b6">
<ul class="org-ul">
<li><p>primitive functions are special</p><p>they explain themself</p><p>and their type is not identified by jojo-head</p></li></ul>
</div>
</div>

<div id="outline-container-orga8b41e8" class="outline-3">
<h3 id="orga8b41e8">define_primitive_function</h3>
<div class="outline-text-3" id="text-orga8b41e8">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">macro</span> <span style="color: #a6e22e;">define_primitive_function</span> string, <span style="color: #a6e22e;">jo</span> {

link__#<span style="color: #a6e22e;">jo</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> link
   link = link__#<span style="color: #a6e22e;">jo</span>

   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #a6e22e;">jo</span>

   ASSEMBLY__length_string string
   .address = current_free_address$string_area
   <span style="color: #66d9ef; font-weight: bold;">xx</span> .address
   <span style="color: #66d9ef; font-weight: bold;">xx</span> .length
   ASSEMBLY__make_string string


   <span style="color: #FF8888;">;; xx (end__#jo - jo)</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #ae81ff;">0</span>

<span style="color: #a6e22e;">jo</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> assembly_code__#<span style="color: #a6e22e;">jo</span>

assembly_code__#<span style="color: #a6e22e;">jo</span>:

   <span style="color: #FF8888;">;; here follows assembly code</span>
   <span style="color: #FF8888;">;; as primitive function body</span>

}
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-org5684749" class="outline-2">
<h2 id="org5684749">variable-jo</h2>
<div class="outline-text-2" id="text-org5684749">
</div><div id="outline-container-org7f78325" class="outline-3">
<h3 id="org7f78325"><span class="todo note">note</span> </h3>
<div class="outline-text-3" id="text-org7f78325">
<ul class="org-ul">
<li><p>no constant</p><p>only variable</p></li>
<li><p>when a variable jo in the jojo</p><p>it push the value of the variable to argument_stack</p></li>
<li><p>when wish to change a variable's value</p><p>use key_word "address" to get the address of the variable</p></li></ul>
</div>
</div>

<div id="outline-container-orgd57b258" class="outline-3">
<h3 id="orgd57b258">define_variable</h3>
<div class="outline-text-3" id="text-orgd57b258">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">macro</span> <span style="color: #a6e22e;">define_variable</span> string, <span style="color: #a6e22e;">jo</span> {

link__#<span style="color: #a6e22e;">jo</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> link
   link = link__#<span style="color: #a6e22e;">jo</span>

   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #a6e22e;">jo</span>

   ASSEMBLY__length_string string
   .address = current_free_address$string_area
   <span style="color: #66d9ef; font-weight: bold;">xx</span> .address
   <span style="color: #66d9ef; font-weight: bold;">xx</span> .length
   ASSEMBLY__make_string string


   <span style="color: #FF8888;">;; length</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #ae81ff;">1</span>

<span style="color: #a6e22e;">jo</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> explain$variable

   <span style="color: #FF8888;">;; here follows a value of cell_size</span>
   <span style="color: #FF8888;">;; only one value is allowed</span>

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org966f410" class="outline-3">
<h3 id="org966f410">explain$variable&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></h3>
<div class="outline-text-3" id="text-org966f410">
<ul class="org-ul">
<li><p><p></p><p>in memory</p><p></p></p><p><table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"></p><p></p><p></p><p><colgroup></p><p><col  class="org-left" /></p><p></colgroup></p><p><tbody></p><p><tr></p><p><td class="org-left">value-1</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">&#x2026;</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">value-n</td></p><p></tr></p><p></tbody></p><p></table></p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =64bit, machine {

<span style="color: #a6e22e;">explain$variable</span>:
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rcx</span>, [<span style="color: #fd971f;">rax</span> + offset__jo$length]
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rax</span>, cell_size
<span style="color: #a6e22e;">.loop</span>:
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rdx</span>, <span style="color: #66d9ef; font-weight: bold;">qword</span> [<span style="color: #fd971f;">rax</span>]
   push_argument_stack <span style="color: #fd971f;">rdx</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rax</span>, cell_size
   <span style="color: #a6e22e;">loop</span> .loop
   next

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org8117cc9" class="outline-3">
<h3 id="org8117cc9">explain$variable&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></h3>
<div class="outline-text-3" id="text-org8117cc9">
<ul class="org-ul">
<li><p><p></p><p>in memory</p><p></p></p><p><table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"></p><p></p><p></p><p><colgroup></p><p><col  class="org-left" /></p><p></colgroup></p><p><tbody></p><p><tr></p><p><td class="org-left">value-1</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">&#x2026;</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">value-n</td></p><p></tr></p><p></tbody></p><p></table></p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =32bit, machine {

<span style="color: #a6e22e;">explain$variable</span>:
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rcx</span>, [<span style="color: #fd971f;">rax</span> + offset__jo$length]
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rax</span>, cell_size
<span style="color: #a6e22e;">.loop</span>:
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rdx</span>, <span style="color: #66d9ef; font-weight: bold;">dword</span> [<span style="color: #fd971f;">rax</span>]
   push_argument_stack <span style="color: #fd971f;">rdx</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rax</span>, cell_size
   <span style="color: #a6e22e;">loop</span> .loop
   next

}
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-org6616390" class="outline-2">
<h2 id="org6616390">jo</h2>
<div class="outline-text-2" id="text-org6616390">
</div><div id="outline-container-org4dd034e" class="outline-3">
<h3 id="org4dd034e">apply</h3>
<div class="outline-text-3" id="text-org4dd034e">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =64bit, machine {

define_primitive_function <span style="color: #e6db74;">"apply"</span>, apply
   <span style="color: #FF8888;">;; &lt;&lt; jo -- unknown &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">jmp</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [<span style="color: #fd971f;">rax</span>]

}


<span style="color: #a6e22e;">match</span> =32bit, machine {

define_primitive_function <span style="color: #e6db74;">"apply"</span>, apply
   <span style="color: #FF8888;">;; &lt;&lt; jo -- unknown &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">eax</span>
   <span style="color: #a6e22e;">jmp</span> <span style="color: #66d9ef; font-weight: bold;">dword</span> [<span style="color: #fd971f;">eax</span>]

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org9bfd5e4" class="outline-3">
<h3 id="org9bfd5e4"><b>cell-size</b></h3>
<div class="outline-text-3" id="text-org9bfd5e4">
<div class="org-src-container">

<pre class="src src-fasm">define_variable <span style="color: #e6db74;">"*cell-size*"</span>, V__cell_size
   <span style="color: #66d9ef; font-weight: bold;">xx</span> cell_size
</pre>
</div>
</div>
</div>

<div id="outline-container-orgd6afee8" class="outline-3">
<h3 id="orgd6afee8">jo-&gt;explainer</h3>
<div class="outline-text-3" id="text-orgd6afee8">
<ul class="org-ul">
<li><p>the type of primitive function jo</p><p>is encoded by 0</p></li>
<li><p>other types of jo</p><p>are encoded by their explainers</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"jo-&gt;explainer"</span>, jo_to_explainer
   <span style="color: #FF8888;">;; &lt;&lt; jo -- type &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>

   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>, get
   <span style="color: #66d9ef; font-weight: bold;">xx</span> swap, subtraction, <span style="color: #f92672; font-weight: bold;">literal</span>, cell_size, equal?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop, zero
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>

   <span style="color: #66d9ef; font-weight: bold;">xx</span> get
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org61e9782" class="outline-3">
<h3 id="org61e9782">jo-&gt;length</h3>
<div class="outline-text-3" id="text-org61e9782">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"jo-&gt;length"</span>, jo_to_length
   <span style="color: #FF8888;">;; &lt;&lt; jo -- length &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, offset__jo$length, addition
   <span style="color: #66d9ef; font-weight: bold;">xx</span> get
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org8274059" class="outline-3">
<h3 id="org8274059">jo,set-length</h3>
<div class="outline-text-3" id="text-org8274059">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"jo,set-length"</span>, jo__set_length
   <span style="color: #FF8888;">;; &lt;&lt; length, jo -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, offset__jo$length, addition
   <span style="color: #66d9ef; font-weight: bold;">xx</span> set
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org93e077f" class="outline-3">
<h3 id="org93e077f">jo-&gt;body</h3>
<div class="outline-text-3" id="text-org93e077f">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"jo-&gt;body"</span>, jo_to_body
   <span style="color: #FF8888;">;; &lt;&lt; jo -- body &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, offset__jo$body
   <span style="color: #66d9ef; font-weight: bold;">xx</span> addition
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orge10e831" class="outline-3">
<h3 id="orge10e831">primitive-function-jo?</h3>
<div class="outline-text-3" id="text-orge10e831">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"primitive-function-jo?"</span>, primitive_function_jo?
   <span style="color: #FF8888;">;; &lt;&lt; jo -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> jo_to_explainer
   <span style="color: #66d9ef; font-weight: bold;">xx</span> zero?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orgaf3016" class="outline-3">
<h3 id="orgaf3016">function-jo?</h3>
<div class="outline-text-3" id="text-orgaf3016">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"function-jo?"</span>, function_jo?
   <span style="color: #FF8888;">;; &lt;&lt; jo -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> jo_to_explainer
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, explain$function
   <span style="color: #66d9ef; font-weight: bold;">xx</span> equal?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org6376de0" class="outline-3">
<h3 id="org6376de0">variable-jo?</h3>
<div class="outline-text-3" id="text-org6376de0">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"variable-jo?"</span>, variable_jo?
   <span style="color: #FF8888;">;; &lt;&lt; jo -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> jo_to_explainer
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, explain$variable
   <span style="color: #66d9ef; font-weight: bold;">xx</span> equal?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orge238ac4" class="outline-3">
<h3 id="orge238ac4">variable-jo-&gt;address</h3>
<div class="outline-text-3" id="text-orge238ac4">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"variable-jo-&gt;address"</span>, variable_jo_to_address
   <span style="color: #FF8888;">;; &lt;&lt; jo -- body &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, offset__jo$body
   <span style="color: #66d9ef; font-weight: bold;">xx</span> addition
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-org931bab6" class="outline-2">
<h2 id="org931bab6">string-area</h2>
<div class="outline-text-2" id="text-org931bab6">
</div><div id="outline-container-org7c60b12" class="outline-3">
<h3 id="org7c60b12"><span class="todo note">note</span> interface</h3>
<div class="outline-text-3" id="text-org7c60b12">
<ul class="org-ul">
<li><p>the interface of string-area is not good</p><p>one can NOT use n-get and n-set</p><p>to get and set value from the address</p></li></ul>
</div>
</div>

<div id="outline-container-org89f8802" class="outline-3">
<h3 id="org89f8802"><b>string-area</b></h3>
<div class="outline-text-3" id="text-org89f8802">
<div class="org-src-container">

<pre class="src src-fasm">define_variable <span style="color: #e6db74;">"*string-area*"</span>, V__string_area
   <span style="color: #66d9ef; font-weight: bold;">xx</span> address$string_area

define_variable <span style="color: #e6db74;">"*string-area,size*"</span>, V__string_area__size
   <span style="color: #66d9ef; font-weight: bold;">xx</span> (end$string_area - address$string_area)

<span style="color: #FF8888;">;; *string-area,current-free-address*</span>
<span style="color: #FF8888;">;; is at epilog</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orgeecc98" class="outline-3">
<h3 id="orgeecc98">string-area,stay</h3>
<div class="outline-text-3" id="text-orgeecc98">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"string-area,stay"</span>, string_area__stay
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> tuck
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__string_area__current_free_address
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string_to_buffer!
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">address</span>, V__string_area__current_free_address
   <span style="color: #66d9ef; font-weight: bold;">xx</span> add_set
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org9a2819d" class="outline-3">
<h3 id="org9a2819d">make-string</h3>
<div class="outline-text-3" id="text-org9a2819d">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"make-string"</span>, make_string
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- string-copy[address, length] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__string_area__current_free_address
   <span style="color: #66d9ef; font-weight: bold;">xx</span> xxswapx
   <span style="color: #66d9ef; font-weight: bold;">xx</span> tuck
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string_area__stay
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-orga454a1d" class="outline-2">
<h2 id="orga454a1d">return-stack</h2>
<div class="outline-text-2" id="text-orga454a1d">
</div><div id="outline-container-org8b8184c" class="outline-3">
<h3 id="org8b8184c"><span class="todo note">note</span> return-point</h3>
<div class="outline-text-3" id="text-org8b8184c">
<ul class="org-ul">
<li><p><p></p><p>structure</p><p></p></p><p><table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"></p><p></p><p></p><p><colgroup></p><p><col  class="org-left" /></p><p></p><p><col  class="org-left" /></p><p></colgroup></p><p><tbody></p><p><tr></p><p><td class="org-left">return-point</td></p><p><td class="org-left">conjugate-local-memory</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">&#xa0;</td></p><p><td class="org-left">local-memory</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">&#xa0;</td></p><p><td class="org-left">local-variable</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">&#xa0;</td></p><p><td class="org-left">jojo</td></p><p></tr></p><p></tbody></p><p></table></p></li>
<li><p>the interface is implemented by needs</p></li></ul>
</div>
</div>

<div id="outline-container-org95e3652" class="outline-3">
<h3 id="org95e3652">offset of return-point</h3>
<div class="outline-text-3" id="text-org95e3652">
<div class="org-src-container">

<pre class="src src-fasm">offset__return_point$conjugate_local_memory   = (cell_size * <span style="color: #ae81ff;">0</span>)
offset__return_point$local_memory             = (cell_size * <span style="color: #ae81ff;">1</span>)
offset__return_point$local_variable           = (cell_size * <span style="color: #ae81ff;">2</span>)
offset__return_point$jojo                     = (cell_size * <span style="color: #ae81ff;">3</span>)

unit__return_point = (cell_size * <span style="color: #ae81ff;">4</span>)
</pre>
</div>
</div>
</div>

<div id="outline-container-org314ce79" class="outline-3">
<h3 id="org314ce79">return-stack:*unit*</h3>
<div class="outline-text-3" id="text-org314ce79">
<div class="org-src-container">

<pre class="src src-fasm">define_variable <span style="color: #e6db74;">"return-stack:*unit*"</span>, V__return_stack__unit
   <span style="color: #66d9ef; font-weight: bold;">xx</span> unit__return_point
</pre>
</div>
</div>
</div>

<div id="outline-container-orgb4cd77" class="outline-3">
<h3 id="orgb4cd77"><span class="todo _">記</span> 插 珠珠 人返回棧 到某珠珠的前面 [等效替換法 以理解]</h3>
<div class="outline-text-3" id="text-orgb4cd77">
<ul class="org-ul">
<li><p>有了下面的 (return-stack:insert-jo) 這個素函數之後</p><p>即便是在非素函數中也能夠對返回棧進行有限的操作了</p></li>
<li><p><p></p><p>before insert-jo</p><p></p></p><p><table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"></p><p></p><p></p><p><colgroup></p><p><col  class="org-left" /></p><p></p><p><col  class="org-left" /></p><p></colgroup></p><p><thead></p><p><tr></p><p><th scope="col" class="org-left">return-point-1</th></p><p><th scope="col" class="org-left">conjugate-local-memory-1</th></p><p></tr></p><p></p><p><tr></p><p><th scope="col" class="org-left">&#xa0;</th></p><p><th scope="col" class="org-left">local-memory-1</th></p><p></tr></p><p></p><p><tr></p><p><th scope="col" class="org-left">&#xa0;</th></p><p><th scope="col" class="org-left">local-variable-1</th></p><p></tr></p><p></p><p><tr></p><p><th scope="col" class="org-left">&#xa0;</th></p><p><th scope="col" class="org-left">jojo-1</th></p><p></tr></p><p></thead></p><p><tbody></p><p><tr></p><p><td class="org-left">return-point-2</td></p><p><td class="org-left">conjugate-local-memory-2</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">&#xa0;</td></p><p><td class="org-left">local-memory-2</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">&#xa0;</td></p><p><td class="org-left">local-variable-2</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">&#xa0;</td></p><p><td class="org-left">jojo-2</td></p><p></tr></p><p></tbody></p><p></table></p></li>
<li><p><p></p><p>after</p><p>jo return-point-2 (return-stack:insert-jo)</p><p></p></p><p><table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"></p><p></p><p></p><p><colgroup></p><p><col  class="org-left" /></p><p></p><p><col  class="org-left" /></p><p></colgroup></p><p><thead></p><p><tr></p><p><th scope="col" class="org-left">return-point-1</th></p><p><th scope="col" class="org-left">conjugate-local-memory-1</th></p><p></tr></p><p></p><p><tr></p><p><th scope="col" class="org-left">&#xa0;</th></p><p><th scope="col" class="org-left">local-memory-1</th></p><p></tr></p><p></p><p><tr></p><p><th scope="col" class="org-left">&#xa0;</th></p><p><th scope="col" class="org-left">local-variable-1</th></p><p></tr></p><p></p><p><tr></p><p><th scope="col" class="org-left">&#xa0;</th></p><p><th scope="col" class="org-left">jojo-1</th></p><p></tr></p><p></thead></p><p><tbody></p><p><tr></p><p><td class="org-left">return-point-in</td></p><p><td class="org-left">conjugate-local-memory-2</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">&#xa0;</td></p><p><td class="org-left">local-memory-2</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">&#xa0;</td></p><p><td class="org-left">local-variable-2</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">&#xa0;</td></p><p><td class="org-left">jojo of jo</td></p><p></tr></p><p></tbody></p><p><tbody></p><p><tr></p><p><td class="org-left">return-point-no</td></p><p><td class="org-left">local-memory-2</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">&#xa0;</td></p><p><td class="org-left">conjugate-local-memory-2</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">&#xa0;</td></p><p><td class="org-left">local-variable-2</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">&#xa0;</td></p><p><td class="org-left">jojo of nothing</td></p><p></tr></p><p></tbody></p><p><tbody></p><p><tr></p><p><td class="org-left">return-point-2</td></p><p><td class="org-left">conjugate-local-memory-2</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">&#xa0;</td></p><p><td class="org-left">local-memory-2</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">&#xa0;</td></p><p><td class="org-left">local-variable-2</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">&#xa0;</td></p><p><td class="org-left">jojo-2</td></p><p></tr></p><p></tbody></p><p></table></p></li>
<li><p>之所以有這樣的效果</p><p>是因爲</p><p>這個 素函數 是爲了 實現 expect 而作</p><p>它可能不具有一般性</p><p>這要看能不能在被插入的珠珠中使用局部變元</p><p>答案看來是肯定的</p><p>但是 這想來並不合理</p><p>爲什麼我能夠隨意在返回棧中插入珠珠</p><p>並且還能在這個珠珠中使用局部變元呢</p><p>下面的考慮方式能夠讓人放心</p><p>即 返回棧中的各個返回點</p><p>是在展開函數體的過程中</p><p>用以記錄調用子函數之後應該返回的地址的</p><p>其中返回點的序關係 記錄了 函數之間的調用關係</p><p>(1) 調用 (2)</p><p>因而 (1) 在 (2) 之前</p><p>然而插入而得的效果</p><p>(1) (in) (2)</p><p>並不是 (1) 調用 (in) 調用 (2)</p><p>(in) 與周圍的兩個函數之間並沒有調用關係</p><p>但是我可以假想出等效的調用關係</p><p>[等效替換法 或 等量代換法]</p><p>即 插入而得的效果</p><p>(1) (in) (2)</p><p>可以被想爲是</p><p>(1) 調用 (in)</p><p>(in) 調用 (2)</p><p>並且 (in) 在調用 (2) 之前</p><p>沒有使用局部數據區域來爲任何局部變元分配空間</p></li>
<li><p>上面的討論就證明了這種實現方式性質良好</p></li></ul>
</div>
</div>

<div id="outline-container-org21a7811" class="outline-3">
<h3 id="org21a7811">nothing</h3>
<div class="outline-text-3" id="text-org21a7811">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"nothing"</span>, nothing
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orgc64671b" class="outline-3">
<h3 id="orgc64671b">return-stack:insert-jo</h3>
<div class="outline-text-3" id="text-orgc64671b">
<ul class="org-ul">
<li><p>先在個循環中複製 return-stack 之後的部分</p><p>以空出一個位置</p><p>然後把 jo 插入到空位</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =64bit, machine {

define_primitive_function <span style="color: #e6db74;">"return-stack:insert-jo"</span>, return_stack__insert_jo
   <span style="color: #FF8888;">;; &lt;&lt; jo, return-stack-pointer -- &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>

   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rsi</span>, pointer$return_stack
   <span style="color: #a6e22e;">add</span> pointer$return_stack, (cell_size * <span style="color: #ae81ff;">4</span> * <span style="color: #ae81ff;">2</span>)
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rdi</span>, pointer$return_stack

<span style="color: #a6e22e;">.loop</span>:
   <span style="color: #a6e22e;">cmp</span> <span style="color: #fd971f;">rbx</span>, <span style="color: #fd971f;">rsi</span>
   <span style="color: #a6e22e;">je</span> .end
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">rsi</span>, cell_size
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">rdi</span>, cell_size
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, <span style="color: #66d9ef; font-weight: bold;">qword</span> [<span style="color: #fd971f;">rsi</span>]
   <span style="color: #a6e22e;">mov</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [<span style="color: #fd971f;">rdi</span>], <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">jmp</span> .loop
<span style="color: #a6e22e;">.end</span>:

   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rax</span>, cell_size
   <span style="color: #a6e22e;">mov</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [<span style="color: #fd971f;">rsi</span> + (cell_size * <span style="color: #ae81ff;">3</span>)], <span style="color: #fd971f;">rax</span>

   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, <span style="color: #66d9ef; font-weight: bold;">qword</span> [<span style="color: #fd971f;">rsi</span> + (cell_size * <span style="color: #ae81ff;">1</span>)]
   <span style="color: #a6e22e;">mov</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [<span style="color: #fd971f;">rsi</span> + (cell_size * <span style="color: #ae81ff;">4</span>)], <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, <span style="color: #66d9ef; font-weight: bold;">qword</span> [<span style="color: #fd971f;">rsi</span> + (cell_size * <span style="color: #ae81ff;">0</span>)]
   <span style="color: #a6e22e;">mov</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [<span style="color: #fd971f;">rsi</span> + (cell_size * <span style="color: #ae81ff;">5</span>)], <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, <span style="color: #66d9ef; font-weight: bold;">qword</span> [<span style="color: #fd971f;">rsi</span> + (cell_size * <span style="color: #ae81ff;">2</span>)]
   <span style="color: #a6e22e;">mov</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [<span style="color: #fd971f;">rsi</span> + (cell_size * <span style="color: #ae81ff;">6</span>)], <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, nothing + cell_size
   <span style="color: #a6e22e;">mov</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [<span style="color: #fd971f;">rsi</span> + (cell_size * <span style="color: #ae81ff;">7</span>)], <span style="color: #fd971f;">rax</span>

   next

}

<span style="color: #a6e22e;">match</span> =32bit, machine {

define_primitive_function <span style="color: #e6db74;">"return-stack:insert-jo"</span>, return_stack__insert_jo
   <span style="color: #FF8888;">;; &lt;&lt; jo, return-stack-pointer -- &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>

   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rcx</span>, [pointer$return_stack]
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rsi</span>, <span style="color: #fd971f;">rcx</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rcx</span>, (cell_size * <span style="color: #ae81ff;">4</span> * <span style="color: #ae81ff;">2</span>)
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rdi</span>, <span style="color: #fd971f;">rcx</span>
   <span style="color: #a6e22e;">mov</span> [pointer$return_stack], <span style="color: #fd971f;">rcx</span>

<span style="color: #a6e22e;">.loop</span>:
   <span style="color: #a6e22e;">cmp</span> <span style="color: #fd971f;">rbx</span>, <span style="color: #fd971f;">rsi</span>
   <span style="color: #a6e22e;">je</span> .end
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">rsi</span>, cell_size
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">rdi</span>, cell_size
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, <span style="color: #66d9ef; font-weight: bold;">dword</span> [<span style="color: #fd971f;">rsi</span>]
   <span style="color: #a6e22e;">mov</span> <span style="color: #66d9ef; font-weight: bold;">dword</span> [<span style="color: #fd971f;">rdi</span>], <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">jmp</span> .loop
<span style="color: #a6e22e;">.end</span>:

   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rax</span>, cell_size
   <span style="color: #a6e22e;">mov</span> <span style="color: #66d9ef; font-weight: bold;">dword</span> [<span style="color: #fd971f;">rsi</span> + (cell_size * <span style="color: #ae81ff;">3</span>)], <span style="color: #fd971f;">rax</span>

   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, <span style="color: #66d9ef; font-weight: bold;">dword</span> [<span style="color: #fd971f;">rsi</span> + (cell_size * <span style="color: #ae81ff;">1</span>)]
   <span style="color: #a6e22e;">mov</span> <span style="color: #66d9ef; font-weight: bold;">dword</span> [<span style="color: #fd971f;">rsi</span> + (cell_size * <span style="color: #ae81ff;">4</span>)], <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, <span style="color: #66d9ef; font-weight: bold;">dword</span> [<span style="color: #fd971f;">rsi</span> + (cell_size * <span style="color: #ae81ff;">0</span>)]
   <span style="color: #a6e22e;">mov</span> <span style="color: #66d9ef; font-weight: bold;">dword</span> [<span style="color: #fd971f;">rsi</span> + (cell_size * <span style="color: #ae81ff;">5</span>)], <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, <span style="color: #66d9ef; font-weight: bold;">dword</span> [<span style="color: #fd971f;">rsi</span> + (cell_size * <span style="color: #ae81ff;">2</span>)]
   <span style="color: #a6e22e;">mov</span> <span style="color: #66d9ef; font-weight: bold;">dword</span> [<span style="color: #fd971f;">rsi</span> + (cell_size * <span style="color: #ae81ff;">6</span>)], <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, nothing + cell_size
   <span style="color: #a6e22e;">mov</span> <span style="color: #66d9ef; font-weight: bold;">dword</span> [<span style="color: #fd971f;">rsi</span> + (cell_size * <span style="color: #ae81ff;">7</span>)], <span style="color: #fd971f;">rax</span>

   next

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org51ae31a" class="outline-3">
<h3 id="org51ae31a">get-return-stack-pointer</h3>
<div class="outline-text-3" id="text-org51ae31a">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =64bit, machine {

define_primitive_function <span style="color: #e6db74;">"get-return-stack-pointer"</span>, get_return_stack_pointer
   push_argument_stack pointer$return_stack
   next

}

<span style="color: #a6e22e;">match</span> =32bit, machine {

define_primitive_function <span style="color: #e6db74;">"get-return-stack-pointer"</span>, get_return_stack_pointer
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [pointer$return_stack]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

}
</pre>
</div>
</div>
</div>

<div id="outline-container-orgb7a880" class="outline-3">
<h3 id="orgb7a880">apply-with-return-point</h3>
<div class="outline-text-3" id="text-orgb7a880">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =64bit, machine {

define_primitive_function <span style="color: #e6db74;">"apply-with-return-point"</span>, apply_with_return_point
   <span style="color: #FF8888;">;; &lt;&lt; return-point, function -- &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">mov</span> pointer$return_stack, <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">jmp</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [<span style="color: #fd971f;">rax</span>]

}

<span style="color: #a6e22e;">match</span> =32bit, machine {

define_primitive_function <span style="color: #e6db74;">"apply-with-return-point"</span>, apply_with_return_point
   <span style="color: #FF8888;">;; &lt;&lt; return-point, function -- &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">mov</span> [pointer$return_stack], <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">jmp</span> <span style="color: #66d9ef; font-weight: bold;">dword</span> [<span style="color: #fd971f;">rax</span>]

}
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-org53b6a21" class="outline-2">
<h2 id="org53b6a21">end &amp; tail-call</h2>
<div class="outline-text-2" id="text-org53b6a21">
</div><div id="outline-container-orge8bd83c" class="outline-3">
<h3 id="orge8bd83c">end</h3>
<div class="outline-text-3" id="text-orge8bd83c">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =64bit, machine {

define_primitive_function <span style="color: #e6db74;">"end"</span>, <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, pointer$return_stack
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">rax</span>, address$return_stack
   <span style="color: #a6e22e;">test</span> <span style="color: #fd971f;">rax</span>, unit__return_point
   <span style="color: #a6e22e;">jnz</span> .return_stack_even

   pop_return_stack <span style="color: #fd971f;">rbx</span>
   pop_return_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> [local_variable$current_free_address], <span style="color: #fd971f;">rax</span>
   pop_return_stack <span style="color: #fd971f;">rax</span>
   pop_return_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> [V__local_memory_odd__current_free_address + cell_size], <span style="color: #fd971f;">rax</span>
   next

<span style="color: #a6e22e;">.return_stack_even</span>:
   pop_return_stack <span style="color: #fd971f;">rbx</span>
   pop_return_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> [local_variable$current_free_address], <span style="color: #fd971f;">rax</span>
   pop_return_stack <span style="color: #fd971f;">rax</span>
   pop_return_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> [V__local_memory_even__current_free_address + cell_size], <span style="color: #fd971f;">rax</span>
   next

}

<span style="color: #a6e22e;">match</span> =32bit, machine {

define_primitive_function <span style="color: #e6db74;">"end"</span>, <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [pointer$return_stack]
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">rax</span>, address$return_stack
   <span style="color: #a6e22e;">test</span> <span style="color: #fd971f;">rax</span>, unit__return_point
   <span style="color: #a6e22e;">jnz</span> .return_stack_even

   pop_return_stack <span style="color: #fd971f;">rbx</span>
   pop_return_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> [local_variable$current_free_address], <span style="color: #fd971f;">rax</span>
   pop_return_stack <span style="color: #fd971f;">rax</span>
   pop_return_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> [V__local_memory_odd__current_free_address + cell_size], <span style="color: #fd971f;">rax</span>
   next

<span style="color: #a6e22e;">.return_stack_even</span>:
   pop_return_stack <span style="color: #fd971f;">rbx</span>
   pop_return_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> [local_variable$current_free_address], <span style="color: #fd971f;">rax</span>
   pop_return_stack <span style="color: #fd971f;">rax</span>
   pop_return_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> [V__local_memory_even__current_free_address + cell_size], <span style="color: #fd971f;">rax</span>
   next

}
</pre>
</div>
</div>
</div>

<div id="outline-container-orgf01085d" class="outline-3">
<h3 id="orgf01085d">tail-call</h3>
<div class="outline-text-3" id="text-orgf01085d">
<ul class="org-ul">
<li><p>tail-call</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =64bit, machine {

define_primitive_function <span style="color: #e6db74;">"tail-call"</span>, <span style="color: #f92672; font-weight: bold;">tail_call</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, pointer$return_stack
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">rax</span>, address$return_stack
   <span style="color: #a6e22e;">test</span> <span style="color: #fd971f;">rax</span>, unit__return_point
   <span style="color: #a6e22e;">jnz</span> .return_stack_even

   pop_return_stack <span style="color: #fd971f;">rbx</span>
   pop_return_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> [local_variable$current_free_address], <span style="color: #fd971f;">rax</span>
   pop_return_stack <span style="color: #fd971f;">rax</span>
   pop_return_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> [V__local_memory_odd__current_free_address + cell_size], <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rbx</span>]
   <span style="color: #a6e22e;">jmp</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [<span style="color: #fd971f;">rax</span>]

<span style="color: #a6e22e;">.return_stack_even</span>:
   pop_return_stack <span style="color: #fd971f;">rbx</span>
   pop_return_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> [local_variable$current_free_address], <span style="color: #fd971f;">rax</span>
   pop_return_stack <span style="color: #fd971f;">rax</span>
   pop_return_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> [V__local_memory_even__current_free_address + cell_size], <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rbx</span>]
   <span style="color: #a6e22e;">jmp</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [<span style="color: #fd971f;">rax</span>]

}

<span style="color: #a6e22e;">match</span> =32bit, machine {

define_primitive_function <span style="color: #e6db74;">"tail-call"</span>, <span style="color: #f92672; font-weight: bold;">tail_call</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [pointer$return_stack]
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">rax</span>, address$return_stack
   <span style="color: #a6e22e;">test</span> <span style="color: #fd971f;">rax</span>, unit__return_point
   <span style="color: #a6e22e;">jnz</span> .return_stack_even

   pop_return_stack <span style="color: #fd971f;">rbx</span>
   pop_return_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> [local_variable$current_free_address], <span style="color: #fd971f;">rax</span>
   pop_return_stack <span style="color: #fd971f;">rax</span>
   pop_return_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> [V__local_memory_odd__current_free_address + cell_size], <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rbx</span>]
   <span style="color: #a6e22e;">jmp</span> <span style="color: #66d9ef; font-weight: bold;">dword</span> [<span style="color: #fd971f;">rax</span>]

<span style="color: #a6e22e;">.return_stack_even</span>:
   pop_return_stack <span style="color: #fd971f;">rbx</span>
   pop_return_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> [local_variable$current_free_address], <span style="color: #fd971f;">rax</span>
   pop_return_stack <span style="color: #fd971f;">rax</span>
   pop_return_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> [V__local_memory_even__current_free_address + cell_size], <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rbx</span>]
   <span style="color: #a6e22e;">jmp</span> <span style="color: #66d9ef; font-weight: bold;">dword</span> [<span style="color: #fd971f;">rax</span>]

}
</pre>
</div>
</div>
</div>

<div id="outline-container-orgbdf3567" class="outline-3">
<h3 id="orgbdf3567"><span class="todo note">note</span> explicit tail call in action</h3>
<div class="outline-text-3" id="text-orgbdf3567">
<ol class="org-ol">
<li>the tail position of a function body must be recognized
explicit tail call is used to achieve this</li>
<li>thus
tail-recursive-call can be use to do loop
without pushing too many address into return-stack</li>
<li><p>
for example if we have a function
which is called "example"
</p>
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"example"</span>, example
   <span style="color: #66d9ef; font-weight: bold;">xx</span> fun1
   <span style="color: #66d9ef; font-weight: bold;">xx</span> fun2
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">tail_call</span>, example
</pre>
</div></li>
<li><p>
and we have the following jojo in return-stack
</p>
<div class="org-src-container">

<pre class="src src-return-stack"><span style="color: #ae81ff; font-weight: bold;">-</span> <span style="color: #dc322f; font-weight: bold;">[</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span> <span style="color: #fd971f; font-weight: bold;">(example)</span> <span style="color: #dc322f; font-weight: bold;">]</span>
          <span style="color: #00ffff; font-weight: bold;">(end)</span>
</pre>
</div></li>
<li><p>
next
</p>
<div class="org-src-container">

<pre class="src src-return-stack">          <span style="color: #ef5939; font-weight: bold;">(example)</span>
<span style="color: #ae81ff; font-weight: bold;">-</span> <span style="color: #dc322f; font-weight: bold;">[</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span> <span style="color: #00ffff; font-weight: bold;">(end)</span> <span style="color: #dc322f; font-weight: bold;">]</span> <span style="color: #ae81ff; font-weight: bold;">-</span> <span style="color: #dc322f; font-weight: bold;">[</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span> <span style="color: #fd971f; font-weight: bold;">(fun1)</span> <span style="color: #dc322f; font-weight: bold;">]</span>
                            <span style="color: #ef5939; font-weight: bold;">(fun2)</span>
                            <span style="color: #ef5939; font-weight: bold;">(tail-call)</span>
                            <span style="color: #ef5939; font-weight: bold;">(example)</span>
</pre>
</div></li>
<li><p>
next
</p>
<div class="org-src-container">

<pre class="src src-return-stack">          <span style="color: #ef5939; font-weight: bold;">(example)</span>         <span style="color: #ef5939; font-weight: bold;">(fun1)</span>
<span style="color: #ae81ff; font-weight: bold;">-</span> <span style="color: #dc322f; font-weight: bold;">[</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span> <span style="color: #00ffff; font-weight: bold;">(end)</span> <span style="color: #dc322f; font-weight: bold;">]</span> <span style="color: #ae81ff; font-weight: bold;">-</span> <span style="color: #dc322f; font-weight: bold;">[</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span> <span style="color: #fd971f; font-weight: bold;">(fun2)</span> <span style="color: #dc322f; font-weight: bold;">]</span>
                            <span style="color: #ef5939; font-weight: bold;">(tail-call)</span>
                            <span style="color: #ef5939; font-weight: bold;">(example)</span>
</pre>
</div></li>
<li><p>
next
</p>
<div class="org-src-container">

<pre class="src src-return-stack">                            <span style="color: #ef5939; font-weight: bold;">(fun1)</span>
          <span style="color: #ef5939; font-weight: bold;">(example)</span>         <span style="color: #ef5939; font-weight: bold;">(fun2)</span>
<span style="color: #ae81ff; font-weight: bold;">-</span> <span style="color: #dc322f; font-weight: bold;">[</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span> <span style="color: #00ffff; font-weight: bold;">(end)</span> <span style="color: #dc322f; font-weight: bold;">]</span> <span style="color: #ae81ff; font-weight: bold;">-</span> <span style="color: #dc322f; font-weight: bold;">[</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span> <span style="color: #fd971f; font-weight: bold;">(tail-call)</span> <span style="color: #dc322f; font-weight: bold;">]</span>
                            <span style="color: #ef5939; font-weight: bold;">(example)</span>
</pre>
</div></li>
<li><p>
next
by the definition of tail_call
</p>
<div class="org-src-container">

<pre class="src src-return-stack">          <span style="color: #ef5939; font-weight: bold;">(example)</span>
<span style="color: #ae81ff; font-weight: bold;">-</span> <span style="color: #dc322f; font-weight: bold;">[</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span> <span style="color: #00ffff; font-weight: bold;">(end)</span> <span style="color: #dc322f; font-weight: bold;">]</span> <span style="color: #ae81ff; font-weight: bold;">-</span> <span style="color: #dc322f; font-weight: bold;">[</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span> <span style="color: #fd971f; font-weight: bold;">(fun1)</span> <span style="color: #dc322f; font-weight: bold;">]</span>
                            <span style="color: #ef5939; font-weight: bold;">(fun2)</span>
                            <span style="color: #ef5939; font-weight: bold;">(tail-call)</span>
                            <span style="color: #ef5939; font-weight: bold;">(example)</span>
</pre>
</div></li>
<li>you can see return-stack of (8.)
is the same as (5.)
it is clear how the example function
is actually a loop now</li></ol>
</div>
</div>
</div>

<div id="outline-container-org7fac706" class="outline-2">
<h2 id="org7fac706">helper function in assembly code</h2>
<div class="outline-text-2" id="text-org7fac706">
</div><div id="outline-container-orga2edc1a" class="outline-3">
<h3 id="orga2edc1a">__exit_with_tos&#xa0;&#xa0;&#xa0;<span class="tag"><span class="linux">linux</span></span></h3>
<div class="outline-text-3" id="text-orga2edc1a">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =linux =64bit, platform machine {

__exit_with_tos:
   <span style="color: #FF8888;">;; &lt;&lt; exit-code -- &gt;&gt;</span>
   pop_argument_stack linux64_sys_1_rdi
   <span style="color: #a6e22e;">mov</span> linux64_sys_n_rax, linux64_syscall_exit
   <span style="color: #a6e22e;">syscall</span>

}

<span style="color: #a6e22e;">match</span> =linux =32bit, platform machine {

__exit_with_tos:
   <span style="color: #FF8888;">;; &lt;&lt; exit-code -- &gt;&gt;</span>
   pop_argument_stack linux32_sys_1_ebx
   <span style="color: #a6e22e;">mov</span> linux32_sys_n_eax, linux32_syscall_exit
   <span style="color: #a6e22e;">syscall</span>

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org494bb2d" class="outline-3">
<h3 id="org494bb2d">__exit_with_zero&#xa0;&#xa0;&#xa0;<span class="tag"><span class="linux">linux</span></span></h3>
<div class="outline-text-3" id="text-org494bb2d">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =linux =64bit, platform machine {

__exit_with_zero:
   <span style="color: #FF8888;">;; &lt;&lt; -- &gt;&gt;</span>
   <span style="color: #a6e22e;">xor</span> linux64_sys_1_rdi, linux64_sys_1_rdi
   <span style="color: #a6e22e;">mov</span> linux64_sys_n_rax, linux64_syscall_exit
   <span style="color: #a6e22e;">syscall</span>

}

<span style="color: #a6e22e;">match</span> =linux =32bit, platform machine {

__exit_with_zero:
   <span style="color: #FF8888;">;; &lt;&lt; -- &gt;&gt;</span>
   <span style="color: #a6e22e;">xor</span> linux32_sys_1_ebx, linux32_sys_1_ebx
   <span style="color: #a6e22e;">mov</span> linux32_sys_n_eax, linux32_syscall_exit
   <span style="color: #a6e22e;">syscall</span>

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org2b92416" class="outline-3">
<h3 id="org2b92416">__exit_with_six&#xa0;&#xa0;&#xa0;<span class="tag"><span class="linux">linux</span></span></h3>
<div class="outline-text-3" id="text-org2b92416">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =linux =64bit, platform machine {

__exit_with_six:
   <span style="color: #FF8888;">;; &lt;&lt; -- &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span> linux64_sys_1_rdi, <span style="color: #ae81ff;">6</span>
   <span style="color: #a6e22e;">mov</span> linux64_sys_n_rax, linux64_syscall_exit
   <span style="color: #a6e22e;">syscall</span>

}

<span style="color: #a6e22e;">match</span> =linux =32bit, platform machine {

__exit_with_six:
   <span style="color: #FF8888;">;; &lt;&lt; -- &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span> linux32_sys_1_ebx, <span style="color: #ae81ff;">6</span>
   <span style="color: #a6e22e;">mov</span> linux32_sys_n_eax, linux32_syscall_exit
   <span style="color: #a6e22e;">syscall</span>

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org3fd2b0a" class="outline-3">
<h3 id="org3fd2b0a">__write_string&#xa0;&#xa0;&#xa0;<span class="tag"><span class="linux">linux</span></span></h3>
<div class="outline-text-3" id="text-org3fd2b0a">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =linux =64bit, platform machine {

__write_string:
   <span style="color: #FF8888;">;; &lt;&lt; address, length -- &gt;&gt;</span>
   pop_argument_stack linux64_sys_3_rdx     <span style="color: #FF8888;">;; max length to be write</span>
   pop_argument_stack linux64_sys_2_rsi     <span style="color: #FF8888;">;; address</span>
   <span style="color: #a6e22e;">mov</span> linux64_sys_1_rdi, <span style="color: #ae81ff;">1</span>                 <span style="color: #FF8888;">;; stdout</span>
   <span style="color: #a6e22e;">mov</span> linux64_sys_n_rax, linux64_syscall_write
   <span style="color: #a6e22e;">syscall</span>
   <span style="color: #a6e22e;">ret</span>

}

<span style="color: #a6e22e;">match</span> =linux =32bit, platform machine {

__write_string:
   <span style="color: #FF8888;">;; &lt;&lt; address, length -- &gt;&gt;</span>
   pop_argument_stack linux32_sys_3_edx     <span style="color: #FF8888;">;; max length to be write</span>
   pop_argument_stack linux32_sys_2_ecx     <span style="color: #FF8888;">;; address</span>
   <span style="color: #a6e22e;">mov</span> linux32_sys_1_ebx, <span style="color: #ae81ff;">1</span>                 <span style="color: #FF8888;">;; stdout</span>
   <span style="color: #a6e22e;">mov</span> linux32_sys_n_eax, linux32_syscall_write
   <span style="color: #a6e22e;">syscall</span>
   <span style="color: #a6e22e;">ret</span>

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org830074" class="outline-3">
<h3 id="org830074">__reset_argument_stack&#xa0;&#xa0;&#xa0;<span class="tag"><span class="linux">linux</span></span></h3>
<div class="outline-text-3" id="text-org830074">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =linux =64bit, platform machine {

__reset_argument_stack:
   <span style="color: #FF8888;">;; &lt;&lt; -- &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span> pointer$argument_stack,  address$argument_stack
   <span style="color: #a6e22e;">ret</span>

}

<span style="color: #a6e22e;">match</span> =linux =32bit, platform machine {

__reset_argument_stack:
   <span style="color: #FF8888;">;; &lt;&lt; -- &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, address$argument_stack
   <span style="color: #a6e22e;">mov</span> [pointer$argument_stack], <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">ret</span>

}
</pre>
</div>
</div>
</div>

<div id="outline-container-orge1bcb73" class="outline-3">
<h3 id="orge1bcb73">__reset_return_stack&#xa0;&#xa0;&#xa0;<span class="tag"><span class="linux">linux</span></span></h3>
<div class="outline-text-3" id="text-orge1bcb73">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =linux =64bit, platform machine {

__reset_return_stack:
   <span style="color: #FF8888;">;; &lt;&lt; -- &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span> pointer$return_stack, address$return_stack
   <span style="color: #a6e22e;">ret</span>

}

<span style="color: #a6e22e;">match</span> =linux =32bit, platform machine {

__reset_return_stack:
   <span style="color: #FF8888;">;; &lt;&lt; -- &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, address$return_stack
   <span style="color: #a6e22e;">mov</span> [pointer$return_stack], <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">ret</span>

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org51ec906" class="outline-3">
<h3 id="org51ec906">__reset_syntax_stack&#xa0;&#xa0;&#xa0;<span class="tag"><span class="linux">linux</span></span></h3>
<div class="outline-text-3" id="text-org51ec906">
<div class="org-src-container">

<pre class="src src-fasm">__reset_syntax_stack:
   <span style="color: #FF8888;">;; &lt;&lt; -- &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, address$syntax_stack
   <span style="color: #a6e22e;">mov</span> [V__syntax_stack__pointer + cell_size], <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">ret</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orgbb189e4" class="outline-3">
<h3 id="orgbb189e4">__reset_local_variable</h3>
<div class="outline-text-3" id="text-orgbb189e4">
<div class="org-src-container">

<pre class="src src-fasm">__reset_local_variable:
   <span style="color: #FF8888;">;; &lt;&lt; -- &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, address$local_variable
   <span style="color: #a6e22e;">mov</span> [local_variable$current_free_address], <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">ret</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org42b0707" class="outline-3">
<h3 id="org42b0707">__reset_local_memory</h3>
<div class="outline-text-3" id="text-org42b0707">
<div class="org-src-container">

<pre class="src src-fasm">__reset_local_memory:
   <span style="color: #FF8888;">;; &lt;&lt; -- &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, address$local_memory_even
   <span style="color: #a6e22e;">mov</span> [V__local_memory_even__current_free_address + cell_size], <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, address$local_memory_odd
   <span style="color: #a6e22e;">mov</span> [V__local_memory_odd__current_free_address + cell_size], <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">ret</span>
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-org65e5db0" class="outline-2">
<h2 id="org65e5db0"><b>the-story-begin</b></h2>
<div class="outline-text-2" id="text-org65e5db0">
</div><div id="outline-container-org91ce231" class="outline-3">
<h3 id="org91ce231"><span class="todo _">記</span> 匯編代碼中的初始化</h3>
<div class="outline-text-3" id="text-org91ce231">
<ul class="org-ul">
<li><p>注意</p><p>所入返回棧的應該是 jojo 而不是 jo</p></li></ul>
</div>
</div>

<div id="outline-container-org1b06f40" class="outline-3">
<h3 id="org1b06f40">begin_to_interpret_threaded_code&#xa0;&#xa0;&#xa0;<span class="tag"><span class="linux">linux</span></span></h3>
<div class="outline-text-3" id="text-org1b06f40">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =linux, platform {

<span style="color: #a6e22e;">begin_to_interpret_threaded_code</span>:

   <span style="color: #a6e22e;">cld</span> <span style="color: #FF8888;">;; set DF = 0, then rsi and rdi are incremented</span>

   <span style="color: #a6e22e;">call</span> __reset_argument_stack
   <span style="color: #a6e22e;">call</span> __reset_return_stack

   pop_return_stack <span style="color: #fd971f;">rax</span>
   pop_return_stack <span style="color: #fd971f;">rax</span>
   pop_return_stack <span style="color: #fd971f;">rax</span>
   pop_return_stack <span style="color: #fd971f;">rax</span>

   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, address$local_memory_odd
   push_return_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, address$local_memory_even
   push_return_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, address$local_variable
   push_return_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, jojo_for__report_return_stack_is_empty_and_exit
   push_return_stack <span style="color: #fd971f;">rax</span>

   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, address$local_memory_even
   push_return_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, address$local_memory_odd
   push_return_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, address$local_variable
   push_return_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, first_jojo
   push_return_stack <span style="color: #fd971f;">rax</span>

   next

<span style="color: #a6e22e;">first_jojo</span>:
   <span style="color: #FF8888;">;; xx little_test</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> initialization
   <span style="color: #66d9ef; font-weight: bold;">xx</span> load_core_file
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">tail_call</span>, basic_REPL

}
</pre>
</div>
</div>
</div>

<div id="outline-container-orga5136c3" class="outline-3">
<h3 id="orga5136c3">initialization</h3>
<div class="outline-text-3" id="text-orga5136c3">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"initialization"</span>, initialization
   <span style="color: #FF8888;">;; &lt;&lt; -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> init__syntax_rule_set__jojo_compiler
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>


<div id="outline-container-org3cfdb28" class="outline-3">
<h3 id="org3cfdb28"><span class="todo note">note</span> top-level-REPL</h3>
<div class="outline-text-3" id="text-org3cfdb28">
<ul class="org-ul">
<li><p><p></p><p>a top-level-REPL always lives at the bottom of return-stack</p><p></p></p><p><div class="org-src-container"></p><p></p><p><pre class="src src-return-stack">          <span style="color: #ef5939; font-weight: bold;">(function)</span></p><p>          <span style="color: #ef5939; font-weight: bold;">(function)</span></p><p><span style="color: #ae81ff; font-weight: bold;">-</span> <span style="color: #dc322f; font-weight: bold;">[</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span> <span style="color: #fd971f; font-weight: bold;">(tail-call)</span> <span style="color: #dc322f; font-weight: bold;">]</span></p><p>          <span style="color: #ef5939; font-weight: bold;">(top-level-REPL)</span></p><p></pre></p><p></div></p></li>
<li><p><p></p><p>right below the return-stack</p><p>there is a (report-return-stack-is-empty-and-exit)</p><p>so actually</p><p></p></p><p><div class="org-src-container"></p><p></p><p><pre class="src src-return-stack">                                                        <span style="color: #ef5939; font-weight: bold;">(function)</span></p><p>                                                        <span style="color: #ef5939; font-weight: bold;">(function)</span></p><p><span style="color: #ae81ff; font-weight: bold;">-</span> <span style="color: #dc322f; font-weight: bold;">[</span> <span style="color: #fd971f; font-weight: bold;">(report-return-stack-is-empty-and-exit)</span> <span style="color: #dc322f; font-weight: bold;">]</span> <span style="color: #ae81ff; font-weight: bold;">-</span> <span style="color: #dc322f; font-weight: bold;">[</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span><span style="color: #fd971f; font-weight: bold;">@</span><span style="color: #dc322f; font-weight: bold;">][</span> <span style="color: #fd971f; font-weight: bold;">(tail-call)</span> <span style="color: #dc322f; font-weight: bold;">]</span></p><p>                                                        <span style="color: #ef5939; font-weight: bold;">(top-level-REPL)</span></p><p></pre></p><p></div></p></li>
<li><p>when you say bye to a top-level-REPL</p><p>(report-return-stack-is-empty-and-exit) will be executed</p></li></ul>
</div>
</div>

<div id="outline-container-org43952a9" class="outline-3">
<h3 id="org43952a9">report-return-stack-is-empty-and-exit</h3>
<div class="outline-text-3" id="text-org43952a9">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">string$report_return_stack_is_empty_and_exit</span>:
   <span style="color: #66d9ef; font-weight: bold;">db</span> <span style="color: #e6db74;">"* the return-stack is empty now"</span>, <span style="color: #ae81ff;">10</span>
   <span style="color: #66d9ef; font-weight: bold;">db</span> <span style="color: #e6db74;">"  good bye ^-^/"</span>, <span style="color: #ae81ff;">10</span>
<span style="color: #a6e22e;">.end</span>:
length$report_return_stack_is_empty_and_exit = (.end - string$report_return_stack_is_empty_and_exit)

define_primitive_function <span style="color: #e6db74;">"report-return-stack-is-empty-and-exit"</span>, report_return_stack_is_empty_and_exit
   <span style="color: #FF8888;">;; &lt;&lt; -- &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, string$report_return_stack_is_empty_and_exit
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rcx</span>, length$report_return_stack_is_empty_and_exit
   push_argument_stack <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rcx</span>
   <span style="color: #a6e22e;">call</span> __write_string
   <span style="color: #a6e22e;">call</span> __exit_with_zero

<span style="color: #a6e22e;">jojo_for__report_return_stack_is_empty_and_exit</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> report_return_stack_is_empty_and_exit
</pre>
</div>
</div>
</div>

<div id="outline-container-org78b3e3d" class="outline-3">
<h3 id="org78b3e3d">reset-top-level-REPL</h3>
<div class="outline-text-3" id="text-org78b3e3d">
<ul class="org-ul">
<li><p>local_variable &amp; local_memory</p><p>will get reseted in by this function</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =64bit, machine {

define_primitive_function <span style="color: #e6db74;">"reset-top-level-REPL"</span>, reset_top_level_REPL
   <span style="color: #FF8888;">;; &lt;&lt; top_level_REPL [jo] -- &gt;&gt;</span>
   <span style="color: #a6e22e;">call</span> __reset_return_stack
   <span style="color: #a6e22e;">call</span> __reset_syntax_stack
   <span style="color: #a6e22e;">call</span> __reset_local_variable
   <span style="color: #a6e22e;">call</span> __reset_local_memory
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">jmp</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [<span style="color: #fd971f;">rax</span>]

}

<span style="color: #a6e22e;">match</span> =32bit, machine {

define_primitive_function <span style="color: #e6db74;">"reset-top-level-REPL"</span>, reset_top_level_REPL
   <span style="color: #FF8888;">;; &lt;&lt; top_level_REPL [jo] -- &gt;&gt;</span>
   <span style="color: #a6e22e;">call</span> __reset_return_stack
   <span style="color: #a6e22e;">call</span> __reset_syntax_stack
   <span style="color: #a6e22e;">call</span> __reset_local_variable
   <span style="color: #a6e22e;">call</span> __reset_local_memory
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">jmp</span> <span style="color: #66d9ef; font-weight: bold;">dword</span> [<span style="color: #fd971f;">rax</span>]

}
</pre>
</div>
</div>
</div>


<div id="outline-container-org7118f6a" class="outline-3">
<h3 id="org7118f6a">exit_with_tos a.k.a. bye</h3>
<div class="outline-text-3" id="text-org7118f6a">
<div class="org-src-container">

<pre class="src src-fasm">define_primitive_function <span style="color: #e6db74;">"bye"</span>, exit_with_tos
   <span style="color: #a6e22e;">call</span> __exit_with_tos
</pre>
</div>
</div>
</div>


<div id="outline-container-org9e400e5" class="outline-3">
<h3 id="org9e400e5">little_test</h3>
<div class="outline-text-3" id="text-org9e400e5">
<div class="org-src-container">

<pre class="src src-fasm">define_variable <span style="color: #e6db74;">""</span>, V__little_test_number
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #ae81ff;">3</span>

define_function <span style="color: #e6db74;">"little_test"</span>, little_test

   <span style="color: #FF8888;">;;;; variable</span>
   <span style="color: #FF8888;">;; xx V__little_test_number</span>
   <span style="color: #FF8888;">;; xx exit_with_tos</span>
   <span style="color: #FF8888;">;;;; exit ocde : 3</span>

   <span style="color: #FF8888;">;;;; literal</span>
   <span style="color: #FF8888;">;; xx literal, 4</span>
   <span style="color: #FF8888;">;; xx exit_with_tos</span>
   <span style="color: #FF8888;">;;;; exit ocde : 4</span>

   <span style="color: #FF8888;">;;;; address</span>
   <span style="color: #FF8888;">;; xx address, V__little_test_number, get, add2</span>
   <span style="color: #FF8888;">;; xx address, V__little_test_number, set</span>
   <span style="color: #FF8888;">;; xx V__little_test_number</span>
   <span style="color: #FF8888;">;; xx exit_with_tos</span>
   <span style="color: #FF8888;">;;;; exit ocde : 5</span>

   <span style="color: #FF8888;">;;;; end</span>
   <span style="color: #FF8888;">;; xx literal, 2, negate</span>
   <span style="color: #FF8888;">;; xx literal, 8</span>
   <span style="color: #FF8888;">;; xx addition</span>
   <span style="color: #FF8888;">;; xx exit_with_tos</span>
   <span style="color: #FF8888;">;;;; 6</span>

   <span style="color: #FF8888;">;;;; tail_call</span>
   <span style="color: #FF8888;">;; xx literal, 2</span>
   <span style="color: #FF8888;">;; xx literal, 4</span>
   <span style="color: #FF8888;">;; xx power</span>
   <span style="color: #FF8888;">;; xx exit_with_tos</span>
   <span style="color: #FF8888;">;;;; exit ocde : 16</span>

   <span style="color: #FF8888;">;;;; write_byte</span>
   <span style="color: #FF8888;">;; xx literal, 64, write_byte</span>
   <span style="color: #FF8888;">;; xx literal, 10, write_byte</span>
   <span style="color: #FF8888;">;; xx zero</span>
   <span style="color: #FF8888;">;; xx exit_with_tos</span>
   <span style="color: #FF8888;">;;;; @</span>

   <span style="color: #FF8888;">;;;; read_byte</span>
   <span style="color: #FF8888;">;; xx read_byte, write_byte</span>
   <span style="color: #FF8888;">;; xx exit_with_tos</span>
   <span style="color: #FF8888;">;;;;</span>

   <span style="color: #FF8888;">;;;; branch</span>
   <span style="color: #FF8888;">;; xx read_byte, write_byte</span>
   <span style="color: #FF8888;">;; xx branch, -3</span>
   <span style="color: #FF8888;">;;;; read a string that ended by &lt;return&gt;</span>
   <span style="color: #FF8888;">;;;; write the readed string</span>
   <span style="color: #FF8888;">;;;; or we can say</span>
   <span style="color: #FF8888;">;;;; read line and write line</span>
   <span style="color: #FF8888;">;;;; or we can say</span>
   <span style="color: #FF8888;">;;;; echo line</span>

   <span style="color: #FF8888;">;;;; false?branch</span>
   <span style="color: #FF8888;">;; xx false, false?branch, 9</span>
   <span style="color: #FF8888;">;; xx   literal, 64, write_byte</span>
   <span style="color: #FF8888;">;; xx   literal, 10, write_byte</span>
   <span style="color: #FF8888;">;; xx   zero</span>
   <span style="color: #FF8888;">;; xx   exit_with_tos</span>
   <span style="color: #FF8888;">;; xx true, false?branch, 9</span>
   <span style="color: #FF8888;">;; xx   literal, 65, write_byte</span>
   <span style="color: #FF8888;">;; xx   literal, 10, write_byte</span>
   <span style="color: #FF8888;">;; xx   zero</span>
   <span style="color: #FF8888;">;; xx   exit_with_tos</span>
   <span style="color: #FF8888;">;; xx zero</span>
   <span style="color: #FF8888;">;; xx exit_with_tos</span>
   <span style="color: #FF8888;">;;;; A</span>

   <span style="color: #FF8888;">;;;; read_word &amp; write_string</span>
   <span style="color: #FF8888;">;; xx read_word, write_string</span>
   <span style="color: #FF8888;">;; xx literal, 10, write_byte</span>
   <span style="color: #FF8888;">;; xx read_word, write_string</span>
   <span style="color: #FF8888;">;; xx literal, 10, write_byte</span>
   <span style="color: #FF8888;">;; xx zero</span>
   <span style="color: #FF8888;">;; xx exit_with_tos</span>
   <span style="color: #FF8888;">;;;; read line</span>
   <span style="color: #FF8888;">;;;; write first two words of the line</span>

   <span style="color: #FF8888;">;;;; string-&gt;integer</span>
   <span style="color: #FF8888;">;; xx read_word, string_to_integer</span>
   <span style="color: #FF8888;">;; xx exit_with_tos</span>
   <span style="color: #FF8888;">;;;; type 123</span>
   <span style="color: #FF8888;">;;;; exit code 123</span>

   <span style="color: #FF8888;">;;;; xxoverxx</span>
   <span style="color: #FF8888;">;; xx literal, 1</span>
   <span style="color: #FF8888;">;; xx literal, 2</span>
   <span style="color: #FF8888;">;; xx literal, 3</span>
   <span style="color: #FF8888;">;; xx literal, 4</span>
   <span style="color: #FF8888;">;; xx xxoverxx</span>
   <span style="color: #FF8888;">;; xx pretty_write_integer</span>
   <span style="color: #FF8888;">;; xx pretty_write_integer</span>
   <span style="color: #FF8888;">;; xx pretty_write_integer</span>
   <span style="color: #FF8888;">;; xx pretty_write_integer</span>
   <span style="color: #FF8888;">;; xx pretty_write_integer</span>
   <span style="color: #FF8888;">;; xx pretty_write_integer</span>
   <span style="color: #FF8888;">;; xx zero</span>
   <span style="color: #FF8888;">;; xx exit_with_tos</span>
   <span style="color: #FF8888;">;;;; 2 1 4 3 2 1</span>

   <span style="color: #FF8888;">;;;; find_link</span>
   <span style="color: #FF8888;">;; xx read_word, string_to_integer ;; number</span>
   <span style="color: #FF8888;">;; xx read_word, string_to_integer ;; number</span>
   <span style="color: #FF8888;">;; xx read_word, V__link, find_link ;; add</span>
   <span style="color: #FF8888;">;; xx drop ;; true</span>
   <span style="color: #FF8888;">;; xx link_to_jo</span>
   <span style="color: #FF8888;">;; xx apply</span>
   <span style="color: #FF8888;">;; xx write_integer</span>
   <span style="color: #FF8888;">;; xx zero</span>
   <span style="color: #FF8888;">;; xx exit_with_tos</span>
   <span style="color: #FF8888;">;;;; 1 2 add</span>
   <span style="color: #FF8888;">;;;; print "3"</span>

   <span style="color: #FF8888;">;;;; basic-REPL (without the ability to define function)</span>
   <span style="color: #FF8888;">;;;; after this test</span>
   <span style="color: #FF8888;">;;;; we will use basic-REPL to do further tests</span>
   <span style="color: #FF8888;">;; xx basic_REPL</span>
   <span style="color: #FF8888;">;;;; 1 2 add .</span>
</pre>
</div>
</div>
</div>
</div>



<div id="outline-container-org9979052" class="outline-2">
<h2 id="org9979052">instruction</h2>
<div class="outline-text-2" id="text-org9979052">
</div><div id="outline-container-orgf896f91" class="outline-3">
<h3 id="orgf896f91"><span class="todo note">note</span> side-effect</h3>
<div class="outline-text-3" id="text-orgf896f91">
<ul class="org-ul">
<li><p>an instruction</p><p>is a special primitive function</p><p>which does special side-effect on return-stack</p></li>
<li><p>note that</p><p>side-effect on return-stack</p><p>should all be done in primitive functions</p></li></ul>
</div>
</div>

<div id="outline-container-org8c93430" class="outline-3">
<h3 id="org8c93430"><span class="todo note">note</span> naming</h3>
<div class="outline-text-3" id="text-org8c93430">
<ul class="org-ul">
<li><p>the naming convention in assembly code</p><p>of instruction</p><p>is the same as it of jo</p></li></ul>
</div>
</div>

<div id="outline-container-orga9c1146" class="outline-3">
<h3 id="orga9c1146">instruction,literal</h3>
<div class="outline-text-3" id="text-orga9c1146">
<div class="org-src-container">

<pre class="src src-fasm">define_primitive_function <span style="color: #e6db74;">"instruction,literal"</span>, <span style="color: #f92672; font-weight: bold;">literal</span>
   <span style="color: #FF8888;">;; &lt;&lt; -- fixnum &gt;&gt;</span>
   pop_return_stack <span style="color: #fd971f;">rbx</span>
     <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rbx</span>]
     push_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rbx</span>, cell_size
   push_return_stack <span style="color: #fd971f;">rbx</span>
   next
</pre>
</div>
</div>
</div>

<div id="outline-container-org761f66" class="outline-3">
<h3 id="org761f66">instruction,address</h3>
<div class="outline-text-3" id="text-org761f66">
<div class="org-src-container">

<pre class="src src-fasm">define_primitive_function <span style="color: #e6db74;">"instruction,address"</span>, <span style="color: #f92672; font-weight: bold;">address</span>
   <span style="color: #FF8888;">;; &lt;&lt; -- address &gt;&gt;</span>
   pop_return_stack <span style="color: #fd971f;">rbx</span>
     <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rbx</span>]
     <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rax</span>, cell_size
     push_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rbx</span>, cell_size
   push_return_stack <span style="color: #fd971f;">rbx</span>
   next
</pre>
</div>
</div>
</div>

<div id="outline-container-orgfce615c" class="outline-3">
<h3 id="orgfce615c">instruction,branch</h3>
<div class="outline-text-3" id="text-orgfce615c">
<div class="org-src-container">

<pre class="src src-fasm">define_primitive_function <span style="color: #e6db74;">"instruction,branch"</span>, <span style="color: #f92672; font-weight: bold;">branch</span>
   pop_return_stack <span style="color: #fd971f;">rbx</span>
     <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rbx</span>]
     <span style="color: #a6e22e;">imul</span> <span style="color: #fd971f;">rax</span>, cell_size
     <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rbx</span>, <span style="color: #fd971f;">rax</span>
   push_return_stack <span style="color: #fd971f;">rbx</span>
   next
</pre>
</div>
</div>
</div>

<div id="outline-container-org75ea086" class="outline-3">
<h3 id="org75ea086">instruction,false?branch</h3>
<div class="outline-text-3" id="text-org75ea086">
<div class="org-src-container">

<pre class="src src-fasm">define_primitive_function <span style="color: #e6db74;">"instruction,false?branch"</span>, <span style="color: #f92672; font-weight: bold;">false?branch</span>
   <span style="color: #FF8888;">;; &lt;&lt; true of false -- &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">test</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">jnz</span> help__false?branch__not_to_branch

   pop_return_stack <span style="color: #fd971f;">rbx</span>
     <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rbx</span>]
     <span style="color: #a6e22e;">imul</span> <span style="color: #fd971f;">rax</span>, cell_size
     <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rbx</span>, <span style="color: #fd971f;">rax</span>
   push_return_stack <span style="color: #fd971f;">rbx</span>
   next

<span style="color: #a6e22e;">help__false?branch__not_to_branch</span>:
   pop_return_stack <span style="color: #fd971f;">rbx</span>
     <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rbx</span>, cell_size
   push_return_stack <span style="color: #fd971f;">rbx</span>
   next
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-orgb634106" class="outline-2">
<h2 id="orgb634106">the stack</h2>
<div class="outline-text-2" id="text-orgb634106">
</div><div id="outline-container-orga60f966" class="outline-3">
<h3 id="orga60f966"><span class="todo note">note</span> </h3>
<div class="outline-text-3" id="text-orga60f966">
<ul class="org-ul">
<li><p>the stack is the argument-stack</p></li></ul>
</div>
</div>

<div id="outline-container-org25675f4" class="outline-3">
<h3 id="org25675f4">drop</h3>
<div class="outline-text-3" id="text-org25675f4">
<div class="org-src-container">

<pre class="src src-fasm">define_primitive_function <span style="color: #e6db74;">"drop"</span>, drop
   <span style="color: #FF8888;">;; &lt;&lt; a -- &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"drop2"</span>, drop2
   <span style="color: #FF8888;">;; &lt;&lt; a b -- &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   next
</pre>
</div>
</div>
</div>

<div id="outline-container-org95f768e" class="outline-3">
<h3 id="org95f768e">dup&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></h3>
<div class="outline-text-3" id="text-org95f768e">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =64bit, machine {

define_primitive_function <span style="color: #e6db74;">"dup"</span>, <span style="color: #f92672; font-weight: bold;">dup</span>
   <span style="color: #FF8888;">;; &lt;&lt; a -- a, a &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span>  <span style="color: #fd971f;">rax</span>, [pointer$argument_stack - (<span style="color: #ae81ff;">1</span> * cell_size)]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"dup2"</span>, dup2
   <span style="color: #FF8888;">;; &lt;&lt; a b -- a b a b &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span>  <span style="color: #fd971f;">rbx</span>, [pointer$argument_stack - (<span style="color: #ae81ff;">1</span> * cell_size)]
   <span style="color: #a6e22e;">mov</span>  <span style="color: #fd971f;">rax</span>, [pointer$argument_stack - (<span style="color: #ae81ff;">2</span> * cell_size)]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rbx</span>
   next

}
</pre>
</div>
</div>
</div>

<div id="outline-container-orgf4db053" class="outline-3">
<h3 id="orgf4db053">dup&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></h3>
<div class="outline-text-3" id="text-orgf4db053">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =32bit, machine {

define_primitive_function <span style="color: #e6db74;">"dup"</span>, <span style="color: #f92672; font-weight: bold;">dup</span>
   <span style="color: #FF8888;">;; &lt;&lt; a -- a a &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"dup2"</span>, dup2
   <span style="color: #FF8888;">;; &lt;&lt; a b -- a b a b &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rbx</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rbx</span>
   next

}
</pre>
</div>
</div>
</div>

<div id="outline-container-orgcec814b" class="outline-3">
<h3 id="orgcec814b">over&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></h3>
<div class="outline-text-3" id="text-orgcec814b">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =64bit, machine {

define_primitive_function <span style="color: #e6db74;">"over"</span>, over
   <span style="color: #FF8888;">;; &lt;&lt; a b -- a b | a &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span>  <span style="color: #fd971f;">rax</span>, [pointer$argument_stack - (<span style="color: #ae81ff;">2</span> * cell_size)]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"x|over|xx"</span>, xoverxx
   <span style="color: #FF8888;">;; &lt;&lt; a | b c -- a | b c | a &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span>  <span style="color: #fd971f;">rax</span>, [pointer$argument_stack - (<span style="color: #ae81ff;">3</span> * cell_size)]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"xx|over|x"</span>, xxoverx
   <span style="color: #FF8888;">;; &lt;&lt; a b | c -- a b | c | a b &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span>  <span style="color: #fd971f;">rax</span>, [pointer$argument_stack - (<span style="color: #ae81ff;">3</span> * cell_size)]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span>  <span style="color: #fd971f;">rax</span>, [pointer$argument_stack - (<span style="color: #ae81ff;">3</span> * cell_size)]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"xx|over|xx"</span>, xxoverxx
   <span style="color: #FF8888;">;; &lt;&lt; a b | c d -- a b | c d | a b &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span>  <span style="color: #fd971f;">rax</span>, [pointer$argument_stack - (<span style="color: #ae81ff;">4</span> * cell_size)]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span>  <span style="color: #fd971f;">rax</span>, [pointer$argument_stack - (<span style="color: #ae81ff;">4</span> * cell_size)]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"x|over|xxx"</span>, xoverxxx
   <span style="color: #FF8888;">;; &lt;&lt; a | b c d -- a | b c d | a &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span>  <span style="color: #fd971f;">rax</span>, [pointer$argument_stack - (<span style="color: #ae81ff;">4</span> * cell_size)]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"x|over|xxxx"</span>, xoverxxxx
   <span style="color: #FF8888;">;; &lt;&lt; a | b c d -- a | b c d | a &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span>  <span style="color: #fd971f;">rax</span>, [pointer$argument_stack - (<span style="color: #ae81ff;">5</span> * cell_size)]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"xx|over|xxxx"</span>, xxoverxxxx
   <span style="color: #FF8888;">;; &lt;&lt; a b | c d e f -- a b | c d e f | a b &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span>  <span style="color: #fd971f;">rax</span>, [pointer$argument_stack - (<span style="color: #ae81ff;">6</span> * cell_size)]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span>  <span style="color: #fd971f;">rax</span>, [pointer$argument_stack - (<span style="color: #ae81ff;">6</span> * cell_size)]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org70c0abf" class="outline-3">
<h3 id="org70c0abf">over&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></h3>
<div class="outline-text-3" id="text-org70c0abf">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =32bit, machine {

define_primitive_function <span style="color: #e6db74;">"over"</span>, over
   <span style="color: #FF8888;">;; &lt;&lt; a b -- a b | a &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [pointer$argument_stack]
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rbx</span> - (<span style="color: #ae81ff;">2</span> * cell_size)]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"x|over|xx"</span>, xoverxx
   <span style="color: #FF8888;">;; &lt;&lt; a | b c -- a | b c | a &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [pointer$argument_stack]
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rbx</span> - (<span style="color: #ae81ff;">3</span> * cell_size)]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"xx|over|x"</span>, xxoverx
   <span style="color: #FF8888;">;; &lt;&lt; a b | c -- a b | c | a b &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [pointer$argument_stack]
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rbx</span> - (<span style="color: #ae81ff;">3</span> * cell_size)]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rbx</span> - (<span style="color: #ae81ff;">2</span> * cell_size)]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"xx|over|xx"</span>, xxoverxx
   <span style="color: #FF8888;">;; &lt;&lt; a b | c d -- a b | c d | a b &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [pointer$argument_stack]
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rbx</span> - (<span style="color: #ae81ff;">4</span> * cell_size)]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rbx</span> - (<span style="color: #ae81ff;">3</span> * cell_size)]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"x|over|xxx"</span>, xoverxxx
   <span style="color: #FF8888;">;; &lt;&lt; a | b c d -- a | b c d | a &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [pointer$argument_stack]
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rbx</span> - (<span style="color: #ae81ff;">4</span> * cell_size)]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"x|over|xxxx"</span>, xoverxxxx
   <span style="color: #FF8888;">;; &lt;&lt; a | b c d -- a | b c d | a &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [pointer$argument_stack]
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rbx</span> - (<span style="color: #ae81ff;">5</span> * cell_size)]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"xx|over|xxxx"</span>, xxoverxxxx
   <span style="color: #FF8888;">;; &lt;&lt; a b | c d e f -- a b | c d e f | a b &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [pointer$argument_stack]
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rbx</span> - (<span style="color: #ae81ff;">6</span> * cell_size)]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rbx</span> - (<span style="color: #ae81ff;">5</span> * cell_size)]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org9caf9fa" class="outline-3">
<h3 id="org9caf9fa">tuck</h3>
<div class="outline-text-3" id="text-org9caf9fa">
<div class="org-src-container">

<pre class="src src-fasm">define_primitive_function <span style="color: #e6db74;">"tuck"</span>, tuck
   <span style="color: #FF8888;">;; &lt;&lt; a b -- b | a b &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rbx</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rbx</span>
   next

define_primitive_function <span style="color: #e6db74;">"x|tuck|xx"</span>, xtuckxx
   <span style="color: #FF8888;">;; &lt;&lt; a | b c -- b c | a | b c &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rcx</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rbx</span>
   push_argument_stack <span style="color: #fd971f;">rcx</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rbx</span>
   push_argument_stack <span style="color: #fd971f;">rcx</span>
   next

define_primitive_function <span style="color: #e6db74;">"xx|tuck|x"</span>, xxtuckx
   <span style="color: #FF8888;">;; &lt;&lt; a b | c -- c | a b | c &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rcx</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rcx</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rbx</span>
   push_argument_stack <span style="color: #fd971f;">rcx</span>
   next

define_primitive_function <span style="color: #e6db74;">"xx|tuck|xx"</span>, xxtuckxx
   <span style="color: #FF8888;">;; &lt;&lt; a b | c d -- c d | a b | c d &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rdx</span>
   pop_argument_stack <span style="color: #fd971f;">rcx</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rcx</span>
   push_argument_stack <span style="color: #fd971f;">rdx</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rbx</span>
   push_argument_stack <span style="color: #fd971f;">rcx</span>
   push_argument_stack <span style="color: #fd971f;">rdx</span>
   next

define_primitive_function <span style="color: #e6db74;">"xxx|tuck|x"</span>, xxxtuckx
   <span style="color: #FF8888;">;; &lt;&lt; a b c | d -- d | a b c | d &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rdx</span>
   pop_argument_stack <span style="color: #fd971f;">rcx</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rdx</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rbx</span>
   push_argument_stack <span style="color: #fd971f;">rcx</span>
   push_argument_stack <span style="color: #fd971f;">rdx</span>
   next

define_primitive_function <span style="color: #e6db74;">"xxxx|tuck|x"</span>, xxxxtuckx
   <span style="color: #FF8888;">;; &lt;&lt; a b c d | e -- e | a b c d | e &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rdi</span> <span style="color: #FF8888;">;; e</span>
   pop_argument_stack <span style="color: #fd971f;">rdx</span>
   pop_argument_stack <span style="color: #fd971f;">rcx</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rdi</span> <span style="color: #FF8888;">;; e</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rbx</span>
   push_argument_stack <span style="color: #fd971f;">rcx</span>
   push_argument_stack <span style="color: #fd971f;">rdx</span>
   push_argument_stack <span style="color: #fd971f;">rdi</span> <span style="color: #FF8888;">;; e</span>
   next
</pre>
</div>
</div>
</div>

<div id="outline-container-org5656ea0" class="outline-3">
<h3 id="org5656ea0">swap</h3>
<div class="outline-text-3" id="text-org5656ea0">
<div class="org-src-container">

<pre class="src src-fasm">define_primitive_function <span style="color: #e6db74;">"swap"</span>, swap
   <span style="color: #FF8888;">;; &lt;&lt; a b -- b a &gt;&gt;</span>
   pop_argument_stack  <span style="color: #fd971f;">rbx</span>
   pop_argument_stack  <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rbx</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"x|swap|xx"</span>, xswapxx
   <span style="color: #FF8888;">;; &lt;&lt; a | b c -- b c | a &gt;&gt;</span>
   pop_argument_stack  <span style="color: #fd971f;">rcx</span>
   pop_argument_stack  <span style="color: #fd971f;">rbx</span>
   pop_argument_stack  <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rbx</span>
   push_argument_stack <span style="color: #fd971f;">rcx</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"xx|swap|x"</span>, xxswapx
   <span style="color: #FF8888;">;; &lt;&lt; a b | c -- c | a b &gt;&gt;</span>
   pop_argument_stack  <span style="color: #fd971f;">rcx</span>
   pop_argument_stack  <span style="color: #fd971f;">rbx</span>
   pop_argument_stack  <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rcx</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rbx</span>
   next

define_primitive_function <span style="color: #e6db74;">"x|swap|xxx"</span>, xswapxxx
   <span style="color: #FF8888;">;; &lt;&lt; a | b c d -- b c d | a &gt;&gt;</span>
   pop_argument_stack  <span style="color: #fd971f;">rdx</span>
   pop_argument_stack  <span style="color: #fd971f;">rcx</span>
   pop_argument_stack  <span style="color: #fd971f;">rbx</span>
   pop_argument_stack  <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rbx</span>
   push_argument_stack <span style="color: #fd971f;">rcx</span>
   push_argument_stack <span style="color: #fd971f;">rdx</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"xxx|swap|x"</span>, xxxswapx
   <span style="color: #FF8888;">;; &lt;&lt; a b c | d -- d | a b c &gt;&gt;</span>
   pop_argument_stack  <span style="color: #fd971f;">rdx</span>
   pop_argument_stack  <span style="color: #fd971f;">rcx</span>
   pop_argument_stack  <span style="color: #fd971f;">rbx</span>
   pop_argument_stack  <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rdx</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rbx</span>
   push_argument_stack <span style="color: #fd971f;">rcx</span>
   next

define_primitive_function <span style="color: #e6db74;">"xx|swap|xx"</span>, xxswapxx
   <span style="color: #FF8888;">;; &lt;&lt; a b | c d -- c d | a b &gt;&gt;</span>
   pop_argument_stack  <span style="color: #fd971f;">rdx</span>
   pop_argument_stack  <span style="color: #fd971f;">rcx</span>
   pop_argument_stack  <span style="color: #fd971f;">rbx</span>
   pop_argument_stack  <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rcx</span>
   push_argument_stack <span style="color: #fd971f;">rdx</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rbx</span>
   next


define_primitive_function <span style="color: #e6db74;">"x|swap|xxxx"</span>, xswapxxxx
   <span style="color: #FF8888;">;; &lt;&lt; a | b c d e -- b c d e | a &gt;&gt;</span>
   pop_argument_stack  <span style="color: #fd971f;">rsi</span> <span style="color: #FF8888;">;; e</span>
   pop_argument_stack  <span style="color: #fd971f;">rdx</span>
   pop_argument_stack  <span style="color: #fd971f;">rcx</span>
   pop_argument_stack  <span style="color: #fd971f;">rbx</span>
   pop_argument_stack  <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rbx</span>
   push_argument_stack <span style="color: #fd971f;">rcx</span>
   push_argument_stack <span style="color: #fd971f;">rdx</span>
   push_argument_stack <span style="color: #fd971f;">rsi</span> <span style="color: #FF8888;">;; e</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"xxxx|swap|x"</span>, xxxxswapx
   <span style="color: #FF8888;">;; &lt;&lt; a b c d | e --  e | a b c d &gt;&gt;</span>
   pop_argument_stack  <span style="color: #fd971f;">rsi</span> <span style="color: #FF8888;">;; e</span>
   pop_argument_stack  <span style="color: #fd971f;">rdx</span>
   pop_argument_stack  <span style="color: #fd971f;">rcx</span>
   pop_argument_stack  <span style="color: #fd971f;">rbx</span>
   pop_argument_stack  <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rsi</span> <span style="color: #FF8888;">;; e</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rbx</span>
   push_argument_stack <span style="color: #fd971f;">rcx</span>
   push_argument_stack <span style="color: #fd971f;">rdx</span>
   next


define_primitive_function <span style="color: #e6db74;">"xx|swap|xxxx"</span>, xxswapxxxx
   <span style="color: #FF8888;">;; &lt;&lt; a b | c d e f -- c d e f | a b &gt;&gt;</span>
   pop_argument_stack  <span style="color: #fd971f;">rsi</span> <span style="color: #FF8888;">;; f</span>
   pop_argument_stack  <span style="color: #fd971f;">rdi</span> <span style="color: #FF8888;">;; e</span>
   pop_argument_stack  <span style="color: #fd971f;">rdx</span>
   pop_argument_stack  <span style="color: #fd971f;">rcx</span>
   pop_argument_stack  <span style="color: #fd971f;">rbx</span>
   pop_argument_stack  <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rcx</span>
   push_argument_stack <span style="color: #fd971f;">rdx</span>
   push_argument_stack <span style="color: #fd971f;">rdi</span> <span style="color: #FF8888;">;; e</span>
   push_argument_stack <span style="color: #fd971f;">rsi</span> <span style="color: #FF8888;">;; f</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rbx</span>
   next

define_primitive_function <span style="color: #e6db74;">"xxxx|swap|xx"</span>, xxxxswapxx
   <span style="color: #FF8888;">;; &lt;&lt; a b c d | e f --  e f | a b c d &gt;&gt;</span>
   pop_argument_stack  <span style="color: #fd971f;">rsi</span> <span style="color: #FF8888;">;; f</span>
   pop_argument_stack  <span style="color: #fd971f;">rdi</span> <span style="color: #FF8888;">;; e</span>
   pop_argument_stack  <span style="color: #fd971f;">rdx</span>
   pop_argument_stack  <span style="color: #fd971f;">rcx</span>
   pop_argument_stack  <span style="color: #fd971f;">rbx</span>
   pop_argument_stack  <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rdi</span> <span style="color: #FF8888;">;; e</span>
   push_argument_stack <span style="color: #fd971f;">rsi</span> <span style="color: #FF8888;">;; f</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rbx</span>
   push_argument_stack <span style="color: #fd971f;">rcx</span>
   push_argument_stack <span style="color: #fd971f;">rdx</span>
   next
</pre>
</div>
</div>
</div>

<div id="outline-container-org81127fe" class="outline-3">
<h3 id="org81127fe">address</h3>
<div class="outline-text-3" id="text-org81127fe">
<div class="org-src-container">

<pre class="src src-fasm">define_variable <span style="color: #e6db74;">"*the-stack*"</span>, V__the_stack
   <span style="color: #66d9ef; font-weight: bold;">xx</span> address$argument_stack
</pre>
</div>
</div>
</div>

<div id="outline-container-org350be05" class="outline-3">
<h3 id="org350be05">pointer</h3>
<div class="outline-text-3" id="text-org350be05">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =64bit, machine {

define_variable <span style="color: #e6db74;">"*the-stack-pointer-snapshot*"</span>, V__the_stack_pointer_snapshot
   <span style="color: #66d9ef; font-weight: bold;">xx</span> address$argument_stack

define_primitive_function <span style="color: #e6db74;">"snapshot-the-stack-pointer"</span>, snapshot_the_stack_pointer
   <span style="color: #FF8888;">;; &lt;&lt; -- &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span> [V__the_stack_pointer_snapshot + cell_size], pointer$argument_stack
   next

}

<span style="color: #a6e22e;">match</span> =32bit, machine {

define_variable <span style="color: #e6db74;">"*the-stack-pointer-snapshot*"</span>, V__the_stack_pointer_snapshot
   <span style="color: #66d9ef; font-weight: bold;">xx</span> address$argument_stack

define_primitive_function <span style="color: #e6db74;">"snapshot-the-stack-pointer"</span>, snapshot_the_stack_pointer
   <span style="color: #FF8888;">;; &lt;&lt; -- &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">eax</span>, [pointer$argument_stack]
   <span style="color: #a6e22e;">mov</span> [V__the_stack_pointer_snapshot + cell_size], <span style="color: #fd971f;">eax</span>
   next

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org8ac64f2" class="outline-3">
<h3 id="org8ac64f2">set-argument-stack-pointer</h3>
<div class="outline-text-3" id="text-org8ac64f2">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =64bit, machine {

define_primitive_function <span style="color: #e6db74;">"set-argument-stack-pointer"</span>, set_argument_stack_pointer
   <span style="color: #FF8888;">;; &lt;&lt; address -- &gt;&gt;</span>
   pop_argument_stack pointer$argument_stack
   next

}

<span style="color: #a6e22e;">match</span> =32bit, machine {

define_primitive_function <span style="color: #e6db74;">"set-argument-stack-pointer"</span>, set_argument_stack_pointer
   <span style="color: #FF8888;">;; &lt;&lt; address -- &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">mov</span> [pointer$argument_stack], <span style="color: #fd971f;">rbx</span>
   next

}
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-orgf29e76f" class="outline-2">
<h2 id="orgf29e76f">bool</h2>
<div class="outline-text-2" id="text-orgf29e76f">
</div><div id="outline-container-org8b60876" class="outline-3">
<h3 id="org8b60876">false &amp; true</h3>
<div class="outline-text-3" id="text-org8b60876">
<ul class="org-ul">
<li><p>they are defined as function</p><p>and viewed as constant</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">define_primitive_function <span style="color: #e6db74;">"false"</span>, false
   <span style="color: #FF8888;">;; &lt;&lt; -- false &gt;&gt;</span>
   <span style="color: #a6e22e;">xor</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"true"</span>, true
   <span style="color: #FF8888;">;; &lt;&lt; -- true &gt;&gt;</span>
   <span style="color: #a6e22e;">xor</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">inc</span> <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next
</pre>
</div>
</div>
</div>

<div id="outline-container-org4eb5b23" class="outline-3">
<h3 id="org4eb5b23">false? &amp; true?</h3>
<div class="outline-text-3" id="text-org4eb5b23">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"false?"</span>, false?
   <span style="color: #FF8888;">;; &lt;&lt; bool -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> false, equal?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>

define_function <span style="color: #e6db74;">"true?"</span>, true?
   <span style="color: #FF8888;">;; &lt;&lt; bool -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> true, equal?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orgac6c0b9" class="outline-3">
<h3 id="orgac6c0b9">and &amp; or &amp; not &amp; xor</h3>
<div class="outline-text-3" id="text-orgac6c0b9">
<ul class="org-ul">
<li><p>the following two functions are for bool value</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"not"</span>, CICADA__not
   <span style="color: #FF8888;">;; &lt;&lt; bool -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> false, equal?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>

define_function <span style="color: #e6db74;">"and"</span>, CICADA__and
   <span style="color: #FF8888;">;; &lt;&lt; bool, bool -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> false?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, (.true-$)/cell_size
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   false
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
<span style="color: #a6e22e;">.true</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">3</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   true
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> false
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>

define_function <span style="color: #e6db74;">"or"</span>, CICADA__or
   <span style="color: #FF8888;">;; &lt;&lt; bool, bool -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">false?branch</span>, (.false-$)/cell_size
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   true
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
<span style="color: #a6e22e;">.false</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">3</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   true
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> false
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>

define_function <span style="color: #e6db74;">"xor"</span>, CICADA__xor
   <span style="color: #FF8888;">;; &lt;&lt; bool, bool -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">false?branch</span>, (.false-$)/cell_size
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   CICADA__not
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
<span style="color: #a6e22e;">.false</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-org6c162c9" class="outline-2">
<h2 id="org6c162c9">fixnum</h2>
<div class="outline-text-2" id="text-org6c162c9">
</div><div id="outline-container-orgcc1e604" class="outline-3">
<h3 id="orgcc1e604">zero &amp; one</h3>
<div class="outline-text-3" id="text-orgcc1e604">
<ul class="org-ul">
<li><p>they are defined as function</p><p>and viewed as constant</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">define_primitive_function <span style="color: #e6db74;">"zero"</span>, zero
   <span style="color: #FF8888;">;; &lt;&lt; -- 0 &gt;&gt;</span>
   <span style="color: #a6e22e;">xor</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"one"</span>, one
   <span style="color: #FF8888;">;; &lt;&lt; -- 1 &gt;&gt;</span>
   <span style="color: #a6e22e;">xor</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">inc</span> <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next
</pre>
</div>
</div>
</div>

<div id="outline-container-orgc5fca29" class="outline-3">
<h3 id="orgc5fca29">zero? &amp; one?</h3>
<div class="outline-text-3" id="text-orgc5fca29">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"zero?"</span>, zero?
   <span style="color: #FF8888;">;; &lt;&lt; bool -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> zero, equal?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>

define_function <span style="color: #e6db74;">"one?"</span>, one?
   <span style="color: #FF8888;">;; &lt;&lt; bool -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> one, equal?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>


<div id="outline-container-orgb88f754" class="outline-3">
<h3 id="orgb88f754">add &amp; sub&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></h3>
<div class="outline-text-3" id="text-orgb88f754">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =64bit, machine {

define_primitive_function <span style="color: #e6db74;">"add1"</span>, add1
   <span style="color: #FF8888;">;; &lt;&lt; n -- n+1 &gt;&gt;</span>
   <span style="color: #a6e22e;">inc</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [pointer$argument_stack - (<span style="color: #ae81ff;">1</span> * cell_size)]
   next

define_primitive_function <span style="color: #e6db74;">"add2"</span>, add2
   <span style="color: #FF8888;">;; &lt;&lt; n -- n+2 &gt;&gt;</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [pointer$argument_stack - (<span style="color: #ae81ff;">1</span> * cell_size)], <span style="color: #ae81ff;">2</span>
   next

define_primitive_function <span style="color: #e6db74;">"add3"</span>, add3
   <span style="color: #FF8888;">;; &lt;&lt; n -- n+3 &gt;&gt;</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [pointer$argument_stack - (<span style="color: #ae81ff;">1</span> * cell_size)], <span style="color: #ae81ff;">3</span>
   next

define_primitive_function <span style="color: #e6db74;">"add4"</span>, add4
   <span style="color: #FF8888;">;; &lt;&lt; n -- n+4 &gt;&gt;</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [pointer$argument_stack - (<span style="color: #ae81ff;">1</span> * cell_size)], <span style="color: #ae81ff;">4</span>
   next

define_primitive_function <span style="color: #e6db74;">"add8"</span>, add8
   <span style="color: #FF8888;">;; &lt;&lt; n -- n+8 &gt;&gt;</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [pointer$argument_stack - (<span style="color: #ae81ff;">1</span> * cell_size)], <span style="color: #ae81ff;">8</span>
   next


define_primitive_function <span style="color: #e6db74;">"sub1"</span>, sub1
   <span style="color: #FF8888;">;; &lt;&lt; n -- n-1 &gt;&gt;</span>
   <span style="color: #a6e22e;">dec</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [pointer$argument_stack - (<span style="color: #ae81ff;">1</span> * cell_size)]
   next

define_primitive_function <span style="color: #e6db74;">"sub2"</span>, sub2
   <span style="color: #FF8888;">;; &lt;&lt; n -- n-2 &gt;&gt;</span>
   <span style="color: #a6e22e;">sub</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [pointer$argument_stack - (<span style="color: #ae81ff;">1</span> * cell_size)], <span style="color: #ae81ff;">2</span>
   next

define_primitive_function <span style="color: #e6db74;">"sub3"</span>, sub3
   <span style="color: #FF8888;">;; &lt;&lt; n -- n-3 &gt;&gt;</span>
   <span style="color: #a6e22e;">sub</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [pointer$argument_stack - (<span style="color: #ae81ff;">1</span> * cell_size)], <span style="color: #ae81ff;">3</span>
   next

define_primitive_function <span style="color: #e6db74;">"sub4"</span>, sub4
   <span style="color: #FF8888;">;; &lt;&lt; n -- n-4 &gt;&gt;</span>
   <span style="color: #a6e22e;">sub</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [pointer$argument_stack - (<span style="color: #ae81ff;">1</span> * cell_size)], <span style="color: #ae81ff;">4</span>
   next

define_primitive_function <span style="color: #e6db74;">"sub8"</span>, sub8
   <span style="color: #FF8888;">;; &lt;&lt; n -- n-8 &gt;&gt;</span>
   <span style="color: #a6e22e;">sub</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [pointer$argument_stack - (<span style="color: #ae81ff;">1</span> * cell_size)], <span style="color: #ae81ff;">8</span>
   next


define_primitive_function <span style="color: #e6db74;">"add"</span>, addition
   <span style="color: #FF8888;">;; &lt;&lt; a b -- a+b &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [pointer$argument_stack - (<span style="color: #ae81ff;">1</span> * cell_size)], <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"sub"</span>, subtraction
   <span style="color: #FF8888;">;; &lt;&lt; a b -- a-b &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">sub</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [pointer$argument_stack - (<span style="color: #ae81ff;">1</span> * cell_size)], <span style="color: #fd971f;">rax</span>
   next

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org7956798" class="outline-3">
<h3 id="org7956798">add &amp; sub&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></h3>
<div class="outline-text-3" id="text-org7956798">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =32bit, machine {

define_primitive_function <span style="color: #e6db74;">"add1"</span>, add1
   <span style="color: #FF8888;">;; &lt;&lt; n -- n+1 &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">inc</span> <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"add2"</span>, add2
   <span style="color: #FF8888;">;; &lt;&lt; n -- n+2 &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">inc</span> <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">inc</span> <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"add3"</span>, add3
   <span style="color: #FF8888;">;; &lt;&lt; n -- n+3 &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">inc</span> <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">inc</span> <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">inc</span> <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"add4"</span>, add4
   <span style="color: #FF8888;">;; &lt;&lt; n -- n+4 &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">inc</span> <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">inc</span> <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">inc</span> <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">inc</span> <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"add8"</span>, add8
   <span style="color: #FF8888;">;; &lt;&lt; n -- n+8 &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rax</span>, <span style="color: #ae81ff;">8</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next


define_primitive_function <span style="color: #e6db74;">"sub1"</span>, sub1
   <span style="color: #FF8888;">;; &lt;&lt; n -- n-1 &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">dec</span> <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"sub2"</span>, sub2
   <span style="color: #FF8888;">;; &lt;&lt; n -- n-2 &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">dec</span> <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">dec</span> <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"sub3"</span>, sub3
   <span style="color: #FF8888;">;; &lt;&lt; n -- n-3 &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">dec</span> <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">dec</span> <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">dec</span> <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"sub4"</span>, sub4
   <span style="color: #FF8888;">;; &lt;&lt; n -- n-4 &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">dec</span> <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">dec</span> <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">dec</span> <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">dec</span> <span style="color: #fd971f;">rax</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"sub8"</span>, sub8
   <span style="color: #FF8888;">;; &lt;&lt; n -- n-8 &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">rax</span>, <span style="color: #ae81ff;">8</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next


define_primitive_function <span style="color: #e6db74;">"add"</span>, addition
   <span style="color: #FF8888;">;; &lt;&lt; a b -- a+b &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">rbx</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"sub"</span>, subtraction
   <span style="color: #FF8888;">;; &lt;&lt; a b -- a-b &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">rbx</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org32f9827" class="outline-3">
<h3 id="org32f9827">mul</h3>
<div class="outline-text-3" id="text-org32f9827">
<div class="org-src-container">

<pre class="src src-fasm">define_primitive_function <span style="color: #e6db74;">"mul"</span>, multiple
   <span style="color: #FF8888;">;; &lt;&lt; a b -- a*b &gt;&gt;</span>
   pop_argument_stack  <span style="color: #fd971f;">rbx</span> <span style="color: #FF8888;">;; 2ed arg</span>
   pop_argument_stack  <span style="color: #fd971f;">rax</span> <span style="color: #FF8888;">;; 1st arg</span>
   <span style="color: #a6e22e;">imul</span> <span style="color: #fd971f;">rbx</span>, <span style="color: #fd971f;">rax</span>
   <span style="color: #FF8888;">;; imul will ignore overflow</span>
   <span style="color: #FF8888;">;; when there are two registers as arg</span>
   <span style="color: #FF8888;">;; imul will set the result into the first register</span>
   push_argument_stack <span style="color: #fd971f;">rbx</span>
   next
</pre>
</div>
</div>
</div>

<div id="outline-container-org7211326" class="outline-3">
<h3 id="org7211326">negate</h3>
<div class="outline-text-3" id="text-org7211326">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"negate"</span>, negate
   <span style="color: #FF8888;">;; &lt;&lt; n --  -n &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> zero
   <span style="color: #66d9ef; font-weight: bold;">xx</span> swap, subtraction
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org291a842" class="outline-3">
<h3 id="org291a842">power</h3>
<div class="outline-text-3" id="text-org291a842">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"power"</span>, power
   <span style="color: #FF8888;">;; n must be nature number for now</span>
   <span style="color: #FF8888;">;; &lt;&lt; a, n -- a^n &gt;&gt;</span>
   <span style="color: #FF8888;">;; 1. when a = 0, n =/= 0</span>
   <span style="color: #FF8888;">;;    the power__loop returns 0</span>
   <span style="color: #FF8888;">;; 2. when a = 0, n = 0</span>
   <span style="color: #FF8888;">;;    the power__loop returns 1</span>
   <span style="color: #FF8888;">;;    but I need it to return 0</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> over, zero?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">3</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">1</span>, swap <span style="color: #FF8888;">;; leave product</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> power__loop
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>

define_function <span style="color: #e6db74;">"power,loop"</span>, power__loop
   <span style="color: #FF8888;">;; &lt;&lt; a, product, n -- a^n &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>, zero?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">5</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop, swap, drop
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> sub1
   <span style="color: #66d9ef; font-weight: bold;">xx</span> swap
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   xoverxx, multiple
   <span style="color: #66d9ef; font-weight: bold;">xx</span> swap
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">tail_call</span>, power__loop
</pre>
</div>
</div>
</div>

<div id="outline-container-orga5a01e4" class="outline-3">
<h3 id="orga5a01e4">div &amp; mod</h3>
<div class="outline-text-3" id="text-orga5a01e4">
<div class="org-src-container">

<pre class="src src-fasm">define_primitive_function <span style="color: #e6db74;">"moddiv"</span>, moddiv
   <span style="color: #FF8888;">;; &lt;&lt; a, b -- a mod b, quotient &gt;&gt;</span>
   <span style="color: #FF8888;">;; &lt;&lt; dividend, divisor -- remainder, quotient &gt;&gt;</span>
   <span style="color: #FF8888;">;; the arg of idiv is divisor</span>
   <span style="color: #FF8888;">;; the lower half of dividend is taken from rax</span>
   <span style="color: #FF8888;">;; the upper half of dividend is taken from rdx</span>
   <span style="color: #a6e22e;">xor</span>  <span style="color: #fd971f;">rdx</span>, <span style="color: #fd971f;">rdx</span>   <span style="color: #FF8888;">;; high-part of dividend is not used</span>
   pop_argument_stack  <span style="color: #fd971f;">rbx</span> <span style="color: #FF8888;">;; 2ed arg</span>
   pop_argument_stack  <span style="color: #fd971f;">rax</span> <span style="color: #FF8888;">;; 1st arg</span>
   <span style="color: #a6e22e;">idiv</span> <span style="color: #fd971f;">rbx</span>
   <span style="color: #FF8888;">;; the remainder is stored in rdx</span>
   <span style="color: #FF8888;">;; the quotient  is stored in rax</span>
   push_argument_stack <span style="color: #fd971f;">rdx</span> <span style="color: #FF8888;">;; remainder</span>
   push_argument_stack <span style="color: #fd971f;">rax</span> <span style="color: #FF8888;">;; quotient</span>
   next


define_function <span style="color: #e6db74;">"divmod"</span>, divmod
   <span style="color: #FF8888;">;; &lt;&lt; a, b -- quotient, a mod b &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> moddiv, swap
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>

define_function <span style="color: #e6db74;">"div"</span>, division
   <span style="color: #FF8888;">;; &lt;&lt; a, b -- quotient &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> divmod, drop
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>

define_function <span style="color: #e6db74;">"mod"</span>, modulo
   <span style="color: #FF8888;">;; &lt;&lt; a, b -- a mod b &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> moddiv, drop
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>


<div id="outline-container-org1b521f6" class="outline-3">
<h3 id="org1b521f6">equal? &amp; greater-than? &amp; less-than?</h3>
<div class="outline-text-3" id="text-org1b521f6">
<div class="org-src-container">

<pre class="src src-fasm">define_primitive_function <span style="color: #e6db74;">"equal?"</span>, equal?
   <span style="color: #FF8888;">;; &lt;&lt; a, b -- bool &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">cmp</span>   <span style="color: #fd971f;">rbx</span>, <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">sete</span>  <span style="color: #fd971f;">al</span>
   <span style="color: #a6e22e;">movzx</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">al</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"less-than?"</span>, less_than?
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">cmp</span>   <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">setl</span>  <span style="color: #fd971f;">al</span>
   <span style="color: #a6e22e;">movzx</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">al</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"greater-than?"</span>, greater_than?
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">cmp</span>   <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">setg</span>  <span style="color: #fd971f;">al</span>
   <span style="color: #a6e22e;">movzx</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">al</span>
   push_argument_stack  <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"less-or-equal?"</span>, less_or_equal?
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">cmp</span>   <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">setle</span> <span style="color: #fd971f;">al</span>
   <span style="color: #a6e22e;">movzx</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">al</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"greater-or-equal?"</span>, greater_or_equal?
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">cmp</span>   <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">setge</span> <span style="color: #fd971f;">al</span>
   <span style="color: #a6e22e;">movzx</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">al</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next
</pre>
</div>
</div>
</div>

<div id="outline-container-orgfbda9e3" class="outline-3">
<h3 id="orgfbda9e3">equal2?</h3>
<div class="outline-text-3" id="text-orgfbda9e3">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"equal2?"</span>, equal2?
   <span style="color: #FF8888;">;; &lt;&lt; a1, b1, a2, b2 -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> xswapxx
   <span style="color: #66d9ef; font-weight: bold;">xx</span> equal?, false?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop2, false
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> equal?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org6c71623" class="outline-3">
<h3 id="org6c71623">negative? &amp; positive?</h3>
<div class="outline-text-3" id="text-org6c71623">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"negative?"</span>, negative?
   <span style="color: #FF8888;">;; &lt;&lt; integer -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> zero, less_than?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>

define_function <span style="color: #e6db74;">"positive?"</span>, positive?
   <span style="color: #FF8888;">;; &lt;&lt; integer -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> zero, greater_than?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org64fa053" class="outline-3">
<h3 id="org64fa053">within?</h3>
<div class="outline-text-3" id="text-org64fa053">
<p>
0 1 2 3 are within 0 3
</p>
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"within?"</span>, within?
   <span style="color: #FF8888;">;; &lt;&lt; x, a, b -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> xoverxx
   <span style="color: #66d9ef; font-weight: bold;">xx</span> greater_or_equal?, CICADA__not, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop2
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   false
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> greater_or_equal?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org8b0c953" class="outline-3">
<h3 id="org8b0c953"><span class="done test">test</span> </h3>
<div class="outline-text-3" id="text-org8b0c953">
<div class="org-src-container">

<pre class="src src-cicada-nymph"><span style="color: #ffff00; font-weight: bold;">:</span> <span style="color: #ef5939; font-weight: bold;">test,within?</span>
  <span style="color: #FF8888;">&lt;&lt; -- &gt;&gt;</span>
  <span style="color: #fd971f; font-weight: bold;">0</span> <span style="color: #fd971f; font-weight: bold;">0</span> <span style="color: #fd971f; font-weight: bold;">3</span> <span style="color: #ffffff; font-weight: bold;">within?</span> .
  <span style="color: #fd971f; font-weight: bold;">1</span> <span style="color: #fd971f; font-weight: bold;">0</span> <span style="color: #fd971f; font-weight: bold;">3</span> <span style="color: #ffffff; font-weight: bold;">within?</span> .
  <span style="color: #fd971f; font-weight: bold;">2</span> <span style="color: #fd971f; font-weight: bold;">0</span> <span style="color: #fd971f; font-weight: bold;">3</span> <span style="color: #ffffff; font-weight: bold;">within?</span> .
  <span style="color: #fd971f; font-weight: bold;">3</span> <span style="color: #fd971f; font-weight: bold;">0</span> <span style="color: #fd971f; font-weight: bold;">3</span> <span style="color: #ffffff; font-weight: bold;">within?</span> .
  .l
  <span style="color: #fd971f; font-weight: bold;">4</span> <span style="color: #fd971f; font-weight: bold;">0</span> <span style="color: #fd971f; font-weight: bold;">3</span>  <span style="color: #ffffff; font-weight: bold;">within?</span> .
  <span style="color: #fd971f; font-weight: bold;">-1</span> <span style="color: #fd971f; font-weight: bold;">0</span> <span style="color: #fd971f; font-weight: bold;">3</span> <span style="color: #ffffff; font-weight: bold;">within?</span> .
  .l
  <span style="color: #00ffff; font-weight: bold;">end</span>
<span style="color: #ffff00; font-weight: bold;">;</span> <span style="color: #ae81ff; font-weight: bold;">define-function</span>
<span style="color: #ffffff; font-weight: bold;">test,within?</span>
</pre>
</div>
</div>
</div>
</div>


<div id="outline-container-org7325ce4" class="outline-2">
<h2 id="org7325ce4">memory</h2>
<div class="outline-text-2" id="text-org7325ce4">
</div><div id="outline-container-org3193e62" class="outline-3">
<h3 id="org3193e62"><span class="todo note">note</span> get &amp; set</h3>
<div class="outline-text-3" id="text-org3193e62">
<ul class="org-ul">
<li><p>although the following functions are all side-effect</p><p>but I use "set" instead of "set!"</p></li>
<li><p>(get) and (set) default to a cell_size</p></li></ul>
</div>
</div>

<div id="outline-container-org2ea6378" class="outline-3">
<h3 id="org2ea6378"><span class="todo note">note</span> endianness of n-get &amp; n-set</h3>
<div class="outline-text-3" id="text-org2ea6378">
<ul class="org-ul">
<li><p><p></p><p>big-endian is used</p><p>in memory</p><p></p></p><p><table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"></p><p></p><p></p><p><colgroup></p><p><col  class="org-left" /></p><p></colgroup></p><p><tbody></p><p><tr></p><p><td class="org-left">value-1</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">value-2</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">value-3</td></p><p></tr></p><p></tbody></p><p></table></p><p><p></p><p>on stack</p><p>&lt;&lt; value-1, value-2, value-3 &gt;&gt;</p><p></p></p></li>
<li><p>thus</p><p>what setd into the address</p><p>will re-occur when geting through the address</p></li>
<li><p>thus</p><p>I do not implement n-get-byte &amp; n-set-byte</p><p>for the endianness of machine</p><p>might not be big-endian</p></li></ul>
</div>
</div>

<div id="outline-container-org3c101e2" class="outline-3">
<h3 id="org3c101e2">get&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></h3>
<div class="outline-text-3" id="text-org3c101e2">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =64bit, machine {

define_primitive_function <span style="color: #e6db74;">"get"</span>, get
   <span style="color: #FF8888;">;; ( address -- value )</span>
   pop_argument_stack  <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rbx</span>]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"get-byte"</span>, get_byte
   <span style="color: #FF8888;">;; ( address -- value )</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">xor</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">al</span>, <span style="color: #66d9ef; font-weight: bold;">byte</span>[<span style="color: #fd971f;">rbx</span>]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"get-two-bytes"</span>, get_two_bytes
   <span style="color: #FF8888;">;; ( address -- value )</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">xor</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">ax</span>, <span style="color: #66d9ef; font-weight: bold;">word</span> [<span style="color: #fd971f;">rbx</span>]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"get-four-bytes"</span>, get_four_bytes
   <span style="color: #FF8888;">;; ( address -- value )</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">xor</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">eax</span>, <span style="color: #66d9ef; font-weight: bold;">dword</span> [<span style="color: #fd971f;">rbx</span>]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"n-get"</span>, n_get
   <span style="color: #FF8888;">;; &lt;&lt; address, n -- value-1, ..., value-n &gt;&gt;</span>
   pop_argument_stack  <span style="color: #fd971f;">rcx</span>
   pop_argument_stack  <span style="color: #fd971f;">rdx</span>
<span style="color: #a6e22e;">.loop</span>:
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, <span style="color: #66d9ef; font-weight: bold;">qword</span> [<span style="color: #fd971f;">rdx</span>]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rdx</span>, cell_size
   <span style="color: #a6e22e;">loop</span> .loop
   next

}
</pre>
</div>
</div>
</div>

<div id="outline-container-orgcd01e4" class="outline-3">
<h3 id="orgcd01e4">set&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></h3>
<div class="outline-text-3" id="text-orgcd01e4">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =64bit, machine {

define_primitive_function <span style="color: #e6db74;">"set"</span>, set
   <span style="color: #FF8888;">;; ( value, address -- )</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> [<span style="color: #fd971f;">rbx</span>], <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"set-byte"</span>, set_byte
   <span style="color: #FF8888;">;; ( value, address -- )</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #66d9ef; font-weight: bold;">byte</span>[<span style="color: #fd971f;">rbx</span>], <span style="color: #fd971f;">al</span>
   next

define_primitive_function <span style="color: #e6db74;">"set-two-bytes"</span>, set_two_bytes
   <span style="color: #FF8888;">;; ( value, address -- )</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #66d9ef; font-weight: bold;">word</span> [<span style="color: #fd971f;">rbx</span>], <span style="color: #fd971f;">ax</span>
   next

define_primitive_function <span style="color: #e6db74;">"set-four-bytes"</span>, set_four_bytes
   <span style="color: #FF8888;">;; ( value, address -- )</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #66d9ef; font-weight: bold;">dword</span> [<span style="color: #fd971f;">rbx</span>], <span style="color: #fd971f;">eax</span>
   next

define_primitive_function <span style="color: #e6db74;">"n-set"</span>, n_set
   <span style="color: #FF8888;">;; &lt;&lt; value-n, ..., value-1, address, n -- &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rcx</span>
   pop_argument_stack <span style="color: #fd971f;">rdx</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, cell_size
   <span style="color: #a6e22e;">imul</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">rcx</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rdx</span>, <span style="color: #fd971f;">rax</span>
   <span style="color: #FF8888;">;; for address is based on 0</span>
   <span style="color: #FF8888;">;; but n is based on 1</span>
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">rdx</span>, cell_size
<span style="color: #a6e22e;">.loop</span>:
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [<span style="color: #fd971f;">rdx</span>], <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">rdx</span>, cell_size
   <span style="color: #a6e22e;">loop</span> .loop
   next

define_primitive_function <span style="color: #e6db74;">"add-set"</span>, add_set
   <span style="color: #FF8888;">;; ( number to add, address -- )</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [<span style="color: #fd971f;">rbx</span>], <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"sub-set"</span>, sub_set
   <span style="color: #FF8888;">;; ( number to sub, address -- )</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">sub</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [<span style="color: #fd971f;">rbx</span>], <span style="color: #fd971f;">rax</span>
   next

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org6dde778" class="outline-3">
<h3 id="org6dde778">get&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></h3>
<div class="outline-text-3" id="text-org6dde778">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =32bit, machine {

define_primitive_function <span style="color: #e6db74;">"get"</span>, get
   <span style="color: #FF8888;">;; ( address -- value )</span>
   pop_argument_stack  <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rbx</span>]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"get-byte"</span>, get_byte
   <span style="color: #FF8888;">;; ( address -- value )</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">xor</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">al</span>, <span style="color: #66d9ef; font-weight: bold;">byte</span>[<span style="color: #fd971f;">rbx</span>]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"get-two-bytes"</span>, get_two_bytes
   <span style="color: #FF8888;">;; ( address -- value )</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">xor</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">ax</span>, <span style="color: #66d9ef; font-weight: bold;">word</span> [<span style="color: #fd971f;">rbx</span>]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"get-four-bytes"</span>, get_four_bytes
   <span style="color: #FF8888;">;; ( address -- value )</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">xor</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">eax</span>, <span style="color: #66d9ef; font-weight: bold;">dword</span> [<span style="color: #fd971f;">rbx</span>]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"n-get"</span>, n_get
   <span style="color: #FF8888;">;; &lt;&lt; address, n -- value-1, ..., value-n &gt;&gt;</span>
   pop_argument_stack  <span style="color: #fd971f;">rcx</span>
   pop_argument_stack  <span style="color: #fd971f;">rdx</span>
<span style="color: #a6e22e;">.loop</span>:
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, <span style="color: #66d9ef; font-weight: bold;">dword</span> [<span style="color: #fd971f;">rdx</span>]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rdx</span>, cell_size
   <span style="color: #a6e22e;">loop</span> .loop
   next

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org9a6bad1" class="outline-3">
<h3 id="org9a6bad1">set&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></h3>
<div class="outline-text-3" id="text-org9a6bad1">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =32bit, machine {

define_primitive_function <span style="color: #e6db74;">"set"</span>, set
   <span style="color: #FF8888;">;; ( value, address -- )</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> [<span style="color: #fd971f;">rbx</span>], <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"set-byte"</span>, set_byte
   <span style="color: #FF8888;">;; ( value, address -- )</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #66d9ef; font-weight: bold;">byte</span>[<span style="color: #fd971f;">rbx</span>], <span style="color: #fd971f;">al</span>
   next

define_primitive_function <span style="color: #e6db74;">"set-two-bytes"</span>, set_two_bytes
   <span style="color: #FF8888;">;; ( value, address -- )</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #66d9ef; font-weight: bold;">word</span> [<span style="color: #fd971f;">rbx</span>], <span style="color: #fd971f;">ax</span>
   next

define_primitive_function <span style="color: #e6db74;">"set-four-bytes"</span>, set_four_bytes
   <span style="color: #FF8888;">;; ( value, address -- )</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #66d9ef; font-weight: bold;">dword</span> [<span style="color: #fd971f;">rbx</span>], <span style="color: #fd971f;">eax</span>
   next

define_primitive_function <span style="color: #e6db74;">"n-set"</span>, n_set
   <span style="color: #FF8888;">;; &lt;&lt; value-n, ..., value-1, address, n -- &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rcx</span>
   pop_argument_stack <span style="color: #fd971f;">rdx</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, cell_size
   <span style="color: #a6e22e;">imul</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">rcx</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rdx</span>, <span style="color: #fd971f;">rax</span>
   <span style="color: #FF8888;">;; for address is based on 0</span>
   <span style="color: #FF8888;">;; but n is based on 1</span>
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">rdx</span>, cell_size
<span style="color: #a6e22e;">.loop</span>:
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #66d9ef; font-weight: bold;">dword</span> [<span style="color: #fd971f;">rdx</span>], <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">rdx</span>, cell_size
   <span style="color: #a6e22e;">loop</span> .loop
   next

define_primitive_function <span style="color: #e6db74;">"add-set"</span>, add_set
   <span style="color: #FF8888;">;; ( number to add, address -- )</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #66d9ef; font-weight: bold;">dword</span> [<span style="color: #fd971f;">rbx</span>], <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"sub-set"</span>, sub_set
   <span style="color: #FF8888;">;; ( number to sub, address -- )</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">sub</span> <span style="color: #66d9ef; font-weight: bold;">dword</span> [<span style="color: #fd971f;">rbx</span>], <span style="color: #fd971f;">rax</span>
   next

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org5984fca" class="outline-3">
<h3 id="org5984fca">clear</h3>
<div class="outline-text-3" id="text-org5984fca">
<div class="org-src-container">

<pre class="src src-fasm">define_primitive_function <span style="color: #e6db74;">"clear-memory"</span>, clear_memory
   <span style="color: #FF8888;">;; &lt;&lt; size, address -- &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rdx</span>
   pop_argument_stack <span style="color: #fd971f;">rcx</span>
   <span style="color: #a6e22e;">xor</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">rax</span>
<span style="color: #a6e22e;">.loop</span>:
   <span style="color: #a6e22e;">mov</span> <span style="color: #66d9ef; font-weight: bold;">byte</span> [<span style="color: #fd971f;">rdx</span>], <span style="color: #fd971f;">al</span>
   <span style="color: #a6e22e;">inc</span> <span style="color: #fd971f;">rdx</span>
   <span style="color: #a6e22e;">dec</span> <span style="color: #fd971f;">rcx</span>
   <span style="color: #a6e22e;">loop</span> .loop
   next
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-org69bb1f1" class="outline-2">
<h2 id="org69bb1f1">bit</h2>
<div class="outline-text-2" id="text-org69bb1f1">
</div><div id="outline-container-org5c163de" class="outline-3">
<h3 id="org5c163de"><span class="todo note">note</span> </h3>
<div class="outline-text-3" id="text-org5c163de">
<ul class="org-ul">
<li><p>xor a.k.a. diff</p></li></ul>
</div>
</div>

<div id="outline-container-org6cbd36c" class="outline-3">
<h3 id="org6cbd36c">or &amp; and &amp; xor &amp; invert&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></h3>
<div class="outline-text-3" id="text-org6cbd36c">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =64bit, machine {

define_primitive_function <span style="color: #e6db74;">"bit-and"</span>, bit_and
   <span style="color: #FF8888;">;; &lt;&lt; a, b -- a and b &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">and</span> [pointer$argument_stack - (<span style="color: #ae81ff;">1</span> * cell_size)], <span style="color: #fd971f;">rbx</span>
   next

define_primitive_function <span style="color: #e6db74;">"bit-or"</span>, bit_or
   <span style="color: #FF8888;">;; &lt;&lt; a, b -- a or b &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">or</span>  [pointer$argument_stack - (<span style="color: #ae81ff;">1</span> * cell_size)], <span style="color: #fd971f;">rbx</span>
   next

define_primitive_function <span style="color: #e6db74;">"bit-xor"</span>, bit_xor
   <span style="color: #FF8888;">;; &lt;&lt; a, b -- a xor b &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">xor</span> [pointer$argument_stack - (<span style="color: #ae81ff;">1</span> * cell_size)], <span style="color: #fd971f;">rbx</span>
   next

define_primitive_function <span style="color: #e6db74;">"bit-invert"</span>, bit_invert
   <span style="color: #FF8888;">;; &lt;&lt; a -- invert a &gt;&gt;</span>
   <span style="color: #a6e22e;">not</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [pointer$argument_stack - (<span style="color: #ae81ff;">1</span> * cell_size)]
   next

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org216c4a9" class="outline-3">
<h3 id="org216c4a9">or &amp; and &amp; xor &amp; invert&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></h3>
<div class="outline-text-3" id="text-org216c4a9">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =32bit, machine {

define_primitive_function <span style="color: #e6db74;">"bit-and"</span>, bit_and
   <span style="color: #FF8888;">;; &lt;&lt; a, b -- a and b &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [pointer$argument_stack]
   <span style="color: #a6e22e;">and</span> [<span style="color: #fd971f;">rax</span> - (<span style="color: #ae81ff;">1</span> * cell_size)], <span style="color: #fd971f;">rbx</span>
   next

define_primitive_function <span style="color: #e6db74;">"bit-or"</span>, bit_or
   <span style="color: #FF8888;">;; &lt;&lt; a, b -- a or b &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [pointer$argument_stack]
   <span style="color: #a6e22e;">or</span>  [<span style="color: #fd971f;">rax</span> - (<span style="color: #ae81ff;">1</span> * cell_size)], <span style="color: #fd971f;">rbx</span>
   next

define_primitive_function <span style="color: #e6db74;">"bit-xor"</span>, bit_xor
   <span style="color: #FF8888;">;; &lt;&lt; a, b -- a xor b &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [pointer$argument_stack]
   <span style="color: #a6e22e;">xor</span> [<span style="color: #fd971f;">rax</span> - (<span style="color: #ae81ff;">1</span> * cell_size)], <span style="color: #fd971f;">rbx</span>
   next

define_primitive_function <span style="color: #e6db74;">"bit-invert"</span>, bit_invert
   <span style="color: #FF8888;">;; &lt;&lt; a -- invert a &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [pointer$argument_stack]
   <span style="color: #a6e22e;">not</span> <span style="color: #66d9ef; font-weight: bold;">dword</span> [<span style="color: #fd971f;">rax</span> - (<span style="color: #ae81ff;">1</span> * cell_size)]
   next

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org97d44dd" class="outline-3">
<h3 id="org97d44dd">left &amp; right[,sign]</h3>
<div class="outline-text-3" id="text-org97d44dd">
<ul class="org-ul">
<li><p>"shl"</p><p>shifts the destination operand left</p><p>by the number of bits specified in the second operand</p><p>The destination operand can be general register or memory</p><p>The second operand can be an immediate value or the CL register</p><p>as bits exit from the left, zeros in from the right</p><p>The last bit that exited is stored in CF</p><p>"sal" is a synonym for "shl"</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">define_primitive_function <span style="color: #e6db74;">"bit-left"</span>, bit_left
   <span style="color: #FF8888;">;; ( fixnum, step -- fixnum * 2^step )</span>
   pop_argument_stack <span style="color: #fd971f;">rcx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">shl</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">cl</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"bit-right"</span>, bit_right
   <span style="color: #FF8888;">;; ( fixnum, step -- fixnum / 2^step )</span>
   pop_argument_stack <span style="color: #fd971f;">rcx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">shr</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">cl</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"bit-right,sign"</span>, bit_right__sign
   <span style="color: #FF8888;">;; ( fixnum, step -- new fixnum )</span>
   pop_argument_stack <span style="color: #fd971f;">rcx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">sar</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">cl</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next
</pre>
</div>
</div>
</div>

<div id="outline-container-orgcd2a178" class="outline-3">
<h3 id="orgcd2a178">get &amp; set &amp; clear &amp; invert</h3>
<div class="outline-text-3" id="text-orgcd2a178">
<ol class="org-ol">
<li>offset is of LSB</li>
<li>offset in [0, &#x2026;, 63]</li>
<li>step   in [1, &#x2026;, 64]</li>
<li>&gt;&lt; need error handling on them</li></ol>
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #FF8888;">;; BT copies a bit from a given register to the carry flag</span>
define_primitive_function <span style="color: #e6db74;">"get-bit"</span>, get_bit
   <span style="color: #FF8888;">;; ( fixnum, offset -- bit )</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">bt</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">setc</span> <span style="color: #fd971f;">al</span>
   <span style="color: #a6e22e;">movzx</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">al</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"set-bit"</span>, set_bit
   <span style="color: #FF8888;">;; ( fixnum, offset -- fixnum )</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">bts</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">rbx</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"clear-bit"</span>, clear_bit
   <span style="color: #FF8888;">;; ( fixnum, offset -- fixnum )</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">btr</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">rbx</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"invert-bit"</span>, invert_bit
   <span style="color: #FF8888;">;; ( fixnum, offset -- fixnum )</span>
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">btc</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">rbx</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next
</pre>
</div>
</div>
</div>

<div id="outline-container-org77ef079" class="outline-3">
<h3 id="org77ef079">find-[lowest|highest]-set-bit</h3>
<div class="outline-text-3" id="text-org77ef079">
<ul class="org-ul">
<li><p>"bsf" "bsr"</p><p>instructions scan a word or double word for first set bit</p><p>and store the index of this bit into destination operand</p><p>which must be general register</p><p>The bit string being scanned is specified by source operand</p><p>it may be either general register or memory</p><p>The ZF flag is set if the entire string is zero (no set bits are found)</p><p>otherwise it is cleared</p></li>
<li><p>If no set bit is found</p><p>the value of the destination register is undefined</p><p>"bsf" scans from low order to high order (starting from bit index zero)</p><p>"bsr" scans from high order to low order</p></li>
<li><p>note that</p><p>if can not find set-bit</p><p>the following functions will return -1</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">define_primitive_function <span style="color: #e6db74;">"find-lowest-set-bit"</span>, find_lowest_set_bit
   <span style="color: #FF8888;">;; ( fixnum -- offset )</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">bsf</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">jz</span> @f
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next
<span style="color: #a6e22e;">@@</span>:
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, -<span style="color: #ae81ff;">1</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"find-highest-set-bit"</span>, find_highest_set_bit
   <span style="color: #FF8888;">;; ( fixnum -- offset )</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">bsr</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">jz</span> @f
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next
<span style="color: #a6e22e;">@@</span>:
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, -<span style="color: #ae81ff;">1</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next
</pre>
</div>
</div>
</div>

<div id="outline-container-orgac93810" class="outline-3">
<h3 id="orgac93810"><span class="done test">test</span> </h3>
<div class="outline-text-3" id="text-orgac93810">
<ul class="org-ul">
<li><p>test is written in cicada-nymph</p><p>for these primitive-functions are added lately</p></li></ul>
<div class="org-src-container">

<pre class="src src-cicada-nymph"><span style="color: #fd971f; font-weight: bold;">2</span><span style="color: #ffff00;">#</span><span style="color: #fd971f; font-weight: bold;">10011001</span> <span style="color: #fd971f; font-weight: bold;">2</span><span style="color: #ffff00;">#</span><span style="color: #fd971f; font-weight: bold;">01100110</span> bit-or  .#2
<span style="color: #fd971f; font-weight: bold;">2</span><span style="color: #ffff00;">#</span><span style="color: #fd971f; font-weight: bold;">10011001</span> <span style="color: #fd971f; font-weight: bold;">2</span><span style="color: #ffff00;">#</span><span style="color: #fd971f; font-weight: bold;">01100110</span> bit-and .#2
<span style="color: #fd971f; font-weight: bold;">2</span><span style="color: #ffff00;">#</span><span style="color: #fd971f; font-weight: bold;">10011001</span> <span style="color: #fd971f; font-weight: bold;">2</span><span style="color: #ffff00;">#</span><span style="color: #fd971f; font-weight: bold;">11111111</span> bit-xor .#2
<span style="color: #fd971f; font-weight: bold;">2</span><span style="color: #ffff00;">#</span><span style="color: #fd971f; font-weight: bold;">10011001</span> <span style="color: #fd971f; font-weight: bold;">2</span><span style="color: #ffff00;">#</span><span style="color: #fd971f; font-weight: bold;">10011001</span> bit-xor .#2

<span style="color: #fd971f; font-weight: bold;">2</span><span style="color: #ffff00;">#</span><span style="color: #fd971f; font-weight: bold;">10011001</span> <span style="color: #fd971f; font-weight: bold;">4</span> bit-left  .#2
<span style="color: #fd971f; font-weight: bold;">2</span><span style="color: #ffff00;">#</span><span style="color: #fd971f; font-weight: bold;">10011001</span> <span style="color: #fd971f; font-weight: bold;">4</span> bit-right .#2
<span style="color: #fd971f; font-weight: bold;">2</span><span style="color: #ffff00;">#</span><span style="color: #fd971f; font-weight: bold;">-10011001</span> <span style="color: #fd971f; font-weight: bold;">4</span> bit-right,sign .#2

<span style="color: #fd971f; font-weight: bold;">2</span><span style="color: #ffff00;">#</span><span style="color: #fd971f; font-weight: bold;">10011001</span> <span style="color: #fd971f; font-weight: bold;">0</span> get-bit .
<span style="color: #fd971f; font-weight: bold;">2</span><span style="color: #ffff00;">#</span><span style="color: #fd971f; font-weight: bold;">10011001</span> <span style="color: #fd971f; font-weight: bold;">1</span> get-bit .
<span style="color: #fd971f; font-weight: bold;">2</span><span style="color: #ffff00;">#</span><span style="color: #fd971f; font-weight: bold;">10011001</span> <span style="color: #fd971f; font-weight: bold;">2</span> get-bit .
<span style="color: #fd971f; font-weight: bold;">2</span><span style="color: #ffff00;">#</span><span style="color: #fd971f; font-weight: bold;">10011001</span> <span style="color: #fd971f; font-weight: bold;">3</span> get-bit .

<span style="color: #fd971f; font-weight: bold;">2</span><span style="color: #ffff00;">#</span><span style="color: #fd971f; font-weight: bold;">10011001</span> <span style="color: #fd971f; font-weight: bold;">0</span> clear-bit .#2
<span style="color: #fd971f; font-weight: bold;">2</span><span style="color: #ffff00;">#</span><span style="color: #fd971f; font-weight: bold;">10011001</span> <span style="color: #fd971f; font-weight: bold;">1</span> set-bit   .#2
<span style="color: #fd971f; font-weight: bold;">2</span><span style="color: #ffff00;">#</span><span style="color: #fd971f; font-weight: bold;">10011001</span> <span style="color: #fd971f; font-weight: bold;">2</span> set-bit   .#2
<span style="color: #fd971f; font-weight: bold;">2</span><span style="color: #ffff00;">#</span><span style="color: #fd971f; font-weight: bold;">10011001</span> <span style="color: #fd971f; font-weight: bold;">3</span> clear-bit .#2

<span style="color: #fd971f; font-weight: bold;">2</span><span style="color: #ffff00;">#</span><span style="color: #fd971f; font-weight: bold;">10011001</span> <span style="color: #fd971f; font-weight: bold;">0</span> invert-bit .#2
<span style="color: #fd971f; font-weight: bold;">2</span><span style="color: #ffff00;">#</span><span style="color: #fd971f; font-weight: bold;">10011001</span> <span style="color: #fd971f; font-weight: bold;">1</span> invert-bit .#2
<span style="color: #fd971f; font-weight: bold;">2</span><span style="color: #ffff00;">#</span><span style="color: #fd971f; font-weight: bold;">10011001</span> <span style="color: #fd971f; font-weight: bold;">2</span> invert-bit .#2
<span style="color: #fd971f; font-weight: bold;">2</span><span style="color: #ffff00;">#</span><span style="color: #fd971f; font-weight: bold;">10011001</span> <span style="color: #fd971f; font-weight: bold;">3</span> invert-bit .#2

<span style="color: #fd971f; font-weight: bold;">2</span><span style="color: #ffff00;">#</span><span style="color: #fd971f; font-weight: bold;">10011000</span> find-lowest-set-bit
<span style="color: #fd971f; font-weight: bold;">2</span><span style="color: #ffff00;">#</span><span style="color: #fd971f; font-weight: bold;">10011000</span> find-highest-set-bit

<span style="color: #fd971f; font-weight: bold;">2</span><span style="color: #ffff00;">#</span><span style="color: #fd971f; font-weight: bold;">00000000</span> find-lowest-set-bit
<span style="color: #fd971f; font-weight: bold;">2</span><span style="color: #ffff00;">#</span><span style="color: #fd971f; font-weight: bold;">00000000</span> find-highest-set-bit
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-orgc0355d9" class="outline-2">
<h2 id="orgc0355d9">write-byte</h2>
<div class="outline-text-2" id="text-orgc0355d9">
</div><div id="outline-container-org5d7a8f9" class="outline-3">
<h3 id="org5d7a8f9">write-byte&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span>&#xa0;<span class="linux">linux</span></span></h3>
<div class="outline-text-3" id="text-org5d7a8f9">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =linux =64bit, platform machine {

<span style="color: #a6e22e;">buffer$write_byte</span>:
   <span style="color: #66d9ef; font-weight: bold;">db</span> <span style="color: #ae81ff;">0</span>

define_primitive_function <span style="color: #e6db74;">"write-byte"</span>, write_byte
   <span style="color: #FF8888;">;; &lt;&lt; byte -- &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #FF8888;">;; write can not just write the byte in al to stdout</span>
   <span style="color: #FF8888;">;; write needs the address of the byte to write</span>
   <span style="color: #a6e22e;">mov</span> [buffer$write_byte], <span style="color: #fd971f;">al</span>
   <span style="color: #a6e22e;">mov</span> linux64_sys_3_rdx, <span style="color: #ae81ff;">1</span>                 <span style="color: #FF8888;">;; max length to be write</span>
   <span style="color: #a6e22e;">mov</span> linux64_sys_2_rsi, buffer$write_byte <span style="color: #FF8888;">;; address</span>
   <span style="color: #a6e22e;">mov</span> linux64_sys_1_rdi, <span style="color: #ae81ff;">1</span>                 <span style="color: #FF8888;">;; stdout</span>
   <span style="color: #a6e22e;">mov</span> linux64_sys_n_rax, linux64_syscall_write
   <span style="color: #a6e22e;">syscall</span>
   next

}
</pre>
</div>
</div>
</div>

<div id="outline-container-orgb063a31" class="outline-3">
<h3 id="orgb063a31">write-byte&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span>&#xa0;<span class="linux">linux</span></span></h3>
<div class="outline-text-3" id="text-orgb063a31">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =linux =32bit, platform machine {

<span style="color: #a6e22e;">buffer$write_byte</span>:
   <span style="color: #66d9ef; font-weight: bold;">db</span> <span style="color: #ae81ff;">0</span>

define_primitive_function <span style="color: #e6db74;">"write-byte"</span>, write_byte
   <span style="color: #FF8888;">;; &lt;&lt; byte -- &gt;&gt;</span>
   <span style="color: #FF8888;">;; just calls the Linux write system call</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #FF8888;">;; write can not just write the byte in al to stdout</span>
   <span style="color: #FF8888;">;; write needs the address of the byte to write</span>
   <span style="color: #a6e22e;">mov</span> [buffer$write_byte], <span style="color: #fd971f;">al</span>
   <span style="color: #a6e22e;">mov</span> linux32_sys_3_edx, <span style="color: #ae81ff;">1</span>                 <span style="color: #FF8888;">;; max length to be write</span>
   <span style="color: #a6e22e;">mov</span> linux32_sys_2_ecx, buffer$write_byte <span style="color: #FF8888;">;; address</span>
   <span style="color: #a6e22e;">mov</span> linux32_sys_1_ebx, <span style="color: #ae81ff;">1</span>                 <span style="color: #FF8888;">;; stdout</span>
   <span style="color: #a6e22e;">mov</span> linux32_sys_n_eax, linux32_syscall_write
   <span style="color: #a6e22e;">syscall</span>
   next

}
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-orgcbd72a1" class="outline-2">
<h2 id="orgcbd72a1">reading-stack</h2>
<div class="outline-text-2" id="text-orgcbd72a1">
</div><div id="outline-container-org4d3f530" class="outline-3">
<h3 id="org4d3f530"><span class="todo note">note</span> </h3>
<div class="outline-text-3" id="text-org4d3f530">
<ul class="org-ul">
<li><p>for we do not build border-check</p><p>into the interface of pop and push</p><p>we allocation some memory below the stacks</p></li>
<li><p>(read-byte) only sees the tos of reading-stack</p></li>
<li><p>reading-stack helps to implement (eval-string)</p><p>push and pop of reading-stack happens in the function (eval-string)</p></li>
<li><p>the interface action on string</p><p>i.e. two values</p></li></ul>
</div>
</div>

<div id="outline-container-orgd655150" class="outline-3">
<h3 id="orgd655150">memory allocation</h3>
<div class="outline-text-3" id="text-orgd655150">
<div class="org-src-container">

<pre class="src src-fasm">size$reading_stack = <span style="color: #ae81ff;">1024</span> * cell_size

   <span style="color: #66d9ef; font-weight: bold;">preserve</span> <span style="color: #ae81ff;">64</span> * cell_size
address$reading_stack <span style="color: #f92672; font-weight: bold;">labeling</span>
   <span style="color: #66d9ef; font-weight: bold;">preserve</span> size$reading_stack

define_variable <span style="color: #e6db74;">"reading-stack:*pointer*"</span>, V__reading_stack__pointer
   <span style="color: #66d9ef; font-weight: bold;">xx</span> address$reading_stack
</pre>
</div>
</div>
</div>

<div id="outline-container-org79c80a9" class="outline-3">
<h3 id="org79c80a9">push &amp; pop &amp; drop&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></h3>
<div class="outline-text-3" id="text-org79c80a9">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =64bit, machine {

define_primitive_function <span style="color: #e6db74;">"push-reading-stack"</span>, push_reading_stack
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [V__reading_stack__pointer + cell_size]
   <span style="color: #a6e22e;">mov</span> [<span style="color: #fd971f;">rbx</span>], <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [V__reading_stack__pointer + cell_size], cell_size
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [V__reading_stack__pointer + cell_size]
   <span style="color: #a6e22e;">mov</span> [<span style="color: #fd971f;">rbx</span>], <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [V__reading_stack__pointer + cell_size], cell_size
   next

define_primitive_function <span style="color: #e6db74;">"pop-reading-stack"</span>, pop_reading_stack
   <span style="color: #FF8888;">;; &lt;&lt; -- string[address, length] &gt;&gt;</span>
   <span style="color: #a6e22e;">sub</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [V__reading_stack__pointer + cell_size], cell_size
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [V__reading_stack__pointer + cell_size]
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rbx</span>]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">sub</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [V__reading_stack__pointer + cell_size], cell_size
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [V__reading_stack__pointer + cell_size]
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rbx</span>]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"drop-reading-stack"</span>, drop_reading_stack
   <span style="color: #FF8888;">;; &lt;&lt; -- &gt;&gt;</span>
   <span style="color: #a6e22e;">sub</span> <span style="color: #66d9ef; font-weight: bold;">qword</span> [V__reading_stack__pointer + cell_size], (cell_size * <span style="color: #ae81ff;">2</span>)
   next

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org27a939c" class="outline-3">
<h3 id="org27a939c">push &amp; pop &amp; drop&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></h3>
<div class="outline-text-3" id="text-org27a939c">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =32bit, machine {

define_primitive_function <span style="color: #e6db74;">"push-reading-stack"</span>, push_reading_stack
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rsi</span>, [V__reading_stack__pointer + cell_size]
   <span style="color: #a6e22e;">mov</span> [<span style="color: #fd971f;">rsi</span>], <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #66d9ef; font-weight: bold;">dword</span> [V__reading_stack__pointer + cell_size], cell_size
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rsi</span>, [V__reading_stack__pointer + cell_size]
   <span style="color: #a6e22e;">mov</span> [<span style="color: #fd971f;">rsi</span>], <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #66d9ef; font-weight: bold;">dword</span> [V__reading_stack__pointer + cell_size], cell_size
   next

define_primitive_function <span style="color: #e6db74;">"pop-reading-stack"</span>, pop_reading_stack
   <span style="color: #FF8888;">;; &lt;&lt; -- string[address, length] &gt;&gt;</span>
   <span style="color: #a6e22e;">sub</span> <span style="color: #66d9ef; font-weight: bold;">dword</span> [V__reading_stack__pointer + cell_size], cell_size
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rsi</span>, [V__reading_stack__pointer + cell_size]
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rsi</span>]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">sub</span> <span style="color: #66d9ef; font-weight: bold;">dword</span> [V__reading_stack__pointer + cell_size], cell_size
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rsi</span>, [V__reading_stack__pointer + cell_size]
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rsi</span>]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

define_primitive_function <span style="color: #e6db74;">"drop-reading-stack"</span>, drop_reading_stack
   <span style="color: #FF8888;">;; &lt;&lt; -- &gt;&gt;</span>
   <span style="color: #a6e22e;">sub</span> <span style="color: #66d9ef; font-weight: bold;">dword</span> [V__reading_stack__pointer + cell_size], (cell_size * <span style="color: #ae81ff;">2</span>)
   next

}
</pre>
</div>
</div>
</div>

<div id="outline-container-orgc6273aa" class="outline-3">
<h3 id="orgc6273aa">tos</h3>
<div class="outline-text-3" id="text-orgc6273aa">
<div class="org-src-container">

<pre class="src src-fasm">define_primitive_function <span style="color: #e6db74;">"tos-reading-stack"</span>, tos_reading_stack
   <span style="color: #FF8888;">;; &lt;&lt; -- string[address, length] &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [V__reading_stack__pointer + cell_size]
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">rbx</span>, cell_size
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rbx</span>]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [V__reading_stack__pointer + cell_size]
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">rbx</span>, cell_size
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">rbx</span>, cell_size
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rbx</span>]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next
</pre>
</div>
</div>
</div>

<div id="outline-container-org3df3f05" class="outline-3">
<h3 id="org3df3f05">reading-stack-empty?</h3>
<div class="outline-text-3" id="text-org3df3f05">
<ul class="org-ul">
<li><p>only one string is in reading-stack and it length is zero</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"reading-stack-empty?"</span>, reading_stack_empty?
   <span style="color: #FF8888;">;; &lt;&lt; -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, V__reading_stack__pointer + cell_size, get
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, address$reading_stack
   <span style="color: #66d9ef; font-weight: bold;">xx</span> equal?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-orgc07c3f9" class="outline-2">
<h2 id="orgc07c3f9">read-byte</h2>
<div class="outline-text-2" id="text-orgc07c3f9">
</div><div id="outline-container-orgee0832" class="outline-3">
<h3 id="orgee0832"><span class="todo note">note</span> end of file</h3>
<div class="outline-text-3" id="text-orgee0832">
<ul class="org-ul">
<li><p>do not exit the program</p><p>when meeting &lt;end-of-file&gt;</p><p>so</p><p>when you hit &lt;C-d&gt;</p><p>some you will not exit the interpreter</p></li></ul>
</div>
</div>

<div id="outline-container-orge656079" class="outline-3">
<h3 id="orge656079"><span class="todo note">note</span> factoring</h3>
<div class="outline-text-3" id="text-orge656079">
<ul class="org-ul">
<li><p>reading from file of stdin is slow</p><p>thus</p><p><ol class="org-ol"></p><p><li>when reading from file</p><p>a whole file is readed at a time</p><p>and setd to a buffer</li></p><p><li>when reading from stdin</p><p>a whole line is readed at a time</li></p><p><li>note that</p><p>reading line instead of keyboard-code</p><p>will limit the design of the user interface</li></ol></p></li>
<li><p>by factoring out the low-level calls</p><p>that read a line from stdin</p><p>we are able to implement eval-string easily</p></li></ul>
</div>
</div>

<div id="outline-container-orgc77e82f" class="outline-3">
<h3 id="orgc77e82f">read-line-from-stdin&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span>&#xa0;<span class="linux">linux</span></span></h3>
<div class="outline-text-3" id="text-orgc77e82f">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =linux =64bit, platform machine {

define_primitive_function <span style="color: #e6db74;">"read-line-from-stdin"</span>, read_line_from_stdin
   <span style="color: #FF8888;">;; &lt;&lt; buffer address, max length -- counter &gt;&gt;</span>
   pop_argument_stack linux64_sys_3_rdx
   pop_argument_stack linux64_sys_2_rsi
   <span style="color: #a6e22e;">xor</span> linux64_sys_1_rdi, linux64_sys_1_rdi <span style="color: #FF8888;">;; stdin</span>
   <span style="color: #a6e22e;">mov</span> linux64_sys_n_rax, linux64_syscall_read
   <span style="color: #a6e22e;">syscall</span>
   <span style="color: #FF8888;">;; the return value</span>
   <span style="color: #FF8888;">;; is a count of the number of bytes transferred</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org7b8311" class="outline-3">
<h3 id="org7b8311">read-line-from-stdin&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span>&#xa0;<span class="linux">linux</span></span></h3>
<div class="outline-text-3" id="text-org7b8311">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =linux =32bit, platform machine {

define_primitive_function <span style="color: #e6db74;">"read-line-from-stdin"</span>, read_line_from_stdin
   <span style="color: #FF8888;">;; &lt;&lt; buffer address, max length -- counter &gt;&gt;</span>
   pop_argument_stack linux32_sys_3_edx
   pop_argument_stack linux32_sys_2_ecx
   <span style="color: #a6e22e;">xor</span> linux32_sys_1_ebx, linux32_sys_1_ebx <span style="color: #FF8888;">;; stdin</span>
   <span style="color: #a6e22e;">mov</span> linux32_sys_n_eax, linux32_syscall_read
   <span style="color: #a6e22e;">syscall</span>
   <span style="color: #FF8888;">;; the return value</span>
   <span style="color: #FF8888;">;; is a count of the number of bytes transferred</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org732a663" class="outline-3">
<h3 id="org732a663"><span class="done test">test</span> read-line-from-stdin</h3>
<div class="outline-text-3" id="text-org732a663">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">""</span>, test__read_line_from_stdin
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, buffer$reading
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, max_input_length
   <span style="color: #66d9ef; font-weight: bold;">xx</span> read_line_from_stdin
   <span style="color: #66d9ef; font-weight: bold;">xx</span> pretty_write_integer
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, buffer$reading
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">10</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> write_string
   <span style="color: #66d9ef; font-weight: bold;">xx</span> exit_with_tos
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orgea3ae1b" class="outline-3">
<h3 id="orgea3ae1b">read-byte</h3>
<div class="outline-text-3" id="text-orgea3ae1b">
<div class="org-src-container">

<pre class="src src-fasm">max_input_length = <span style="color: #ae81ff;">64</span> * <span style="color: #ae81ff;">1024</span>

buffer$reading <span style="color: #f92672; font-weight: bold;">labeling</span>
   <span style="color: #66d9ef; font-weight: bold;">preserve</span> max_input_length

replace$reading <span style="color: #f92672; font-weight: bold;">labeling</span>
   <span style="color: #66d9ef; font-weight: bold;">preserve</span> <span style="color: #ae81ff;">1024</span>

define_function <span style="color: #e6db74;">"read-byte"</span>, read_byte
   <span style="color: #FF8888;">;; &lt;&lt; -- byte &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> pop_reading_stack
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2, empty_string?, CICADA__not, <span style="color: #f92672; font-weight: bold;">false?branch</span>, (.bad_tos-$)/cell_size
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   sub1, swap
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   tuck
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   add1, swap
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   push_reading_stack
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   get_byte
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
<span style="color: #a6e22e;">.bad_tos</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> reading_stack_empty?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, (.not_empty-$)/cell_size
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop2
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, buffer$reading
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, max_input_length
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   read_line_from_stdin
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">dup</span>, positive?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, (.read_error-$)/cell_size
   <span style="color: #66d9ef; font-weight: bold;">xx</span>     <span style="color: #f92672; font-weight: bold;">literal</span>, buffer$reading
   <span style="color: #66d9ef; font-weight: bold;">xx</span>     swap
   <span style="color: #66d9ef; font-weight: bold;">xx</span>     push_reading_stack
   <span style="color: #66d9ef; font-weight: bold;">xx</span>     <span style="color: #f92672; font-weight: bold;">tail_call</span>, read_byte
<span style="color: #a6e22e;">.read_error</span>:
   <span style="color: #FF8888;">;;   ignore &lt;end-of-file&gt;</span>
   <span style="color: #FF8888;">;;   ignore reading error</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, buffer$reading
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">0</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   push_reading_stack
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">tail_call</span>, read_byte
<span style="color: #a6e22e;">.not_empty</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, error$read_byte
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, length$read_byte
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   write_string
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, replace$reading
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">1024</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   read_line_from_stdin
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, replace$reading
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   swap
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   push_reading_stack
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">tail_call</span>, read_byte

<span style="color: #a6e22e;">error$read_byte</span>:
   <span style="color: #66d9ef; font-weight: bold;">db</span> <span style="color: #e6db74;">"* (read-byte) meets empty-string in reading-stack"</span>, <span style="color: #ae81ff;">10</span>
   <span style="color: #66d9ef; font-weight: bold;">db</span> <span style="color: #e6db74;">"  and this empty-stack is not at the bottom of the reading-stack"</span>, <span style="color: #ae81ff;">10</span>
   <span style="color: #66d9ef; font-weight: bold;">db</span> <span style="color: #e6db74;">"  you can type a line to replace this empty string"</span>, <span style="color: #ae81ff;">10</span>
<span style="color: #a6e22e;">.end</span>:
length$read_byte = (.end - error$read_byte)
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-orgf9c337e" class="outline-2">
<h2 id="orgf9c337e">load-core-file</h2>
<div class="outline-text-2" id="text-orgf9c337e">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"load-core-file"</span>, load_core_file
   <span style="color: #FF8888;">;; &lt;&lt; unknown -- unknown &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, address$core_file
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, (end$core_file - address$core_file)
   <span style="color: #66d9ef; font-weight: bold;">xx</span> push_reading_stack
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orgc1cf5a1" class="outline-2">
<h2 id="orgc1cf5a1">byte</h2>
<div class="outline-text-2" id="text-orgc1cf5a1">
</div><div id="outline-container-org762ce7c" class="outline-3">
<h3 id="org762ce7c">space-byte?</h3>
<div class="outline-text-3" id="text-org762ce7c">
<ul class="org-ul">
<li><p>as for space-byte</p><p>I only use two</p><p>ASCII 10 (newline)</p><p>ASCII 32 (whitespace)</p></li>
<li><p>note that</p><p>I use the term "whitespace" to denotes the byte</p><p>I use the term "space" to denotes the set of bytes</p></li>
<li><p>I will simply view number less-or-equal 32 as space-byte</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"space-byte?"</span>, space_byte?
   <span style="color: #FF8888;">;; &lt;&lt; byte -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">0</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">32</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> within?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orga43063f" class="outline-3">
<h3 id="orga43063f">bar-ket-byte?</h3>
<div class="outline-text-3" id="text-orga43063f">
<ul class="org-ul">
<li><p>() [] {}</p><p>but not &lt;&gt;</p></li>
<li><p>double-quote is viewed as special bar-ket-byte</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"bar-ket-byte?"</span>, bar_ket_byte?
   <span style="color: #FF8888;">;; &lt;&lt; byte -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>, <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #e6db74;">'('</span>, equal?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop, true
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>, <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #e6db74;">')'</span>, equal?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop, true
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>, <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #e6db74;">'['</span>, equal?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop, true
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>, <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #e6db74;">']'</span>, equal?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop, true
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>, <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #e6db74;">'{'</span>, equal?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop, true
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>, <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #e6db74;">'}'</span>, equal?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop, true
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>, <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #e6db74;">'"'</span>, equal?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop, true
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> drop, false
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orgb485ae1" class="outline-3">
<h3 id="orgb485ae1">digit-byte?</h3>
<div class="outline-text-3" id="text-orgb485ae1">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"digit-byte?"</span>, digit_byte?
   <span style="color: #FF8888;">;; &lt;&lt; byte -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #e6db74;">'0'</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #e6db74;">'9'</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> within?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org281a9cf" class="outline-3">
<h3 id="org281a9cf">digit-byte-&gt;number &amp; number-&gt;digit-byte</h3>
<div class="outline-text-3" id="text-org281a9cf">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"digit-byte-&gt;number"</span>, digit_byte_to_number
   <span style="color: #FF8888;">;; &lt;&lt; byte -- number &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #e6db74;">'0'</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> subtraction
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>

define_function <span style="color: #e6db74;">"number-&gt;digit-byte"</span>, number_to_digit_byte
   <span style="color: #FF8888;">;; &lt;&lt; number -- byte &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #e6db74;">'0'</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> addition
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-org7e84198" class="outline-2">
<h2 id="org7e84198">buffer</h2>
<div class="outline-text-2" id="text-org7e84198">
</div><div id="outline-container-orgf962804" class="outline-3">
<h3 id="orgf962804"><span class="todo note">note</span> </h3>
<div class="outline-text-3" id="text-orgf962804">
<ul class="org-ul">
<li><p>a buffer is a large vector</p><p>and some functions do not care about how large it is</p></li></ul>
</div>
</div>

<div id="outline-container-orga9b45d8" class="outline-3">
<h3 id="orga9b45d8">compare-buffer</h3>
<div class="outline-text-3" id="text-orga9b45d8">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #FF8888;">;; return false when length == 0</span>
define_primitive_function <span style="color: #e6db74;">"compare-buffer"</span>, compare_buffer
   <span style="color: #FF8888;">;; &lt;&lt; address, address, length -- bool &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rcx</span>
   pop_argument_stack <span style="color: #fd971f;">rdi</span>
   pop_argument_stack <span style="color: #fd971f;">rsi</span>
   <span style="color: #a6e22e;">repe</span> <span style="color: #a6e22e;">cmpsb</span>
   <span style="color: #a6e22e;">sete</span> <span style="color: #fd971f;">al</span>
   <span style="color: #a6e22e;">movzx</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">al</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next
</pre>
</div>
</div>
</div>

<div id="outline-container-org988a4fe" class="outline-3">
<h3 id="org988a4fe">cursor-&gt;next-matching-byte</h3>
<div class="outline-text-3" id="text-org988a4fe">
<ul class="org-ul">
<li><p>note that</p><p>it is the NEXT matching-byte</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"cursor-&gt;next-matching-byte"</span>, cursor_to_next_matching_byte
   <span style="color: #FF8888;">;; &lt;&lt; cursor, byte -- cursor new address &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> over, add1, get_byte
   <span style="color: #66d9ef; font-weight: bold;">xx</span> over, equal?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop, add1
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> swap
   <span style="color: #66d9ef; font-weight: bold;">xx</span> add1, swap
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">tail_call</span>, cursor_to_next_matching_byte
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-org5a87b1e" class="outline-2">
<h2 id="org5a87b1e">string</h2>
<div class="outline-text-2" id="text-org5a87b1e">
</div><div id="outline-container-orgf212cde" class="outline-3">
<h3 id="orgf212cde"><span class="todo note">note</span> io about string</h3>
</div>

<div id="outline-container-org77c5d74" class="outline-3">
<h3 id="org77c5d74">write-string</h3>
<div class="outline-text-3" id="text-org77c5d74">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"write-string"</span>, write_string
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>, zero?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">3</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop2
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> sub1, swap
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>, get_byte, write_byte
   <span style="color: #66d9ef; font-weight: bold;">xx</span> add1, swap
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">tail_call</span>, write_string

define_function <span style="color: #e6db74;">".s"</span>, ALIAS__write_string
   <span style="color: #FF8888;">;; &lt;&lt; integer -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> write_string
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orgfab5f36" class="outline-3">
<h3 id="orgfab5f36">pretty_write_string</h3>
<div class="outline-text-3" id="text-orgfab5f36">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"pretty-write-string"</span>, pretty_write_string
   <span style="color: #FF8888;">;; &lt;&lt; integer -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> write_string
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">10</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> write_byte
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>


<div id="outline-container-org801cbe4" class="outline-3">
<h3 id="org801cbe4">string:empty?</h3>
<div class="outline-text-3" id="text-org801cbe4">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"string:empty?"</span>, empty_string?
  <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- bool &gt;&gt;</span>
  <span style="color: #66d9ef; font-weight: bold;">xx</span> swap, drop
  <span style="color: #66d9ef; font-weight: bold;">xx</span> zero?
  <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org2a47304" class="outline-3">
<h3 id="org2a47304">string:equal?</h3>
<div class="outline-text-3" id="text-org2a47304">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"string:equal?"</span>, string_equal?
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length], string[address, length] -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> xoverxx, equal?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   swap
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   compare_buffer
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> drop, drop2
   <span style="color: #66d9ef; font-weight: bold;">xx</span> false
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org5f47d33" class="outline-3">
<h3 id="org5f47d33">string:byte</h3>
<div class="outline-text-3" id="text-org5f47d33">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"string:byte"</span>, string__byte
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- byte &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> drop, get_byte
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org4049599" class="outline-3">
<h3 id="org4049599">string:byte-tail</h3>
<div class="outline-text-3" id="text-org4049599">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"string:byte-tail"</span>, string__byte_tail
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- [address + 1, length - 1] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> sub1, swap
   <span style="color: #66d9ef; font-weight: bold;">xx</span> add1
   <span style="color: #66d9ef; font-weight: bold;">xx</span> swap
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org7d68499" class="outline-3">
<h3 id="org7d68499">string:byte-back</h3>
<div class="outline-text-3" id="text-org7d68499">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"string:byte-back"</span>, string__byte_back
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- [address - 1, length + 1] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> add1, swap
   <span style="color: #66d9ef; font-weight: bold;">xx</span> sub1
   <span style="color: #66d9ef; font-weight: bold;">xx</span> swap
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>


<div id="outline-container-org47630ca" class="outline-3">
<h3 id="org47630ca">string-&gt;buffer!</h3>
<div class="outline-text-3" id="text-org47630ca">
<div class="org-src-container">

<pre class="src src-fasm">define_primitive_function <span style="color: #e6db74;">"string-&gt;buffer!"</span>, string_to_buffer!
   <span style="color: #FF8888;">;; ( string[address, length], buffer[address] -- )</span>
   pop_argument_stack <span style="color: #fd971f;">rdi</span> <span style="color: #FF8888;">;; destination</span>
   pop_argument_stack <span style="color: #fd971f;">rcx</span> <span style="color: #FF8888;">;; counter</span>
   pop_argument_stack <span style="color: #fd971f;">rsi</span> <span style="color: #FF8888;">;; source</span>
   <span style="color: #a6e22e;">rep</span> <span style="color: #a6e22e;">movsb</span>
   next
</pre>
</div>
</div>
</div>

<div id="outline-container-orgc1d10ef" class="outline-3">
<h3 id="orgc1d10ef">string-reverse!&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></h3>
<div class="outline-text-3" id="text-orgc1d10ef">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =64bit, machine {

buffer$string_reverse! <span style="color: #f92672; font-weight: bold;">labeling</span>
   <span style="color: #66d9ef; font-weight: bold;">preserve</span> <span style="color: #ae81ff;">1024</span>


define_primitive_function <span style="color: #e6db74;">"string-reverse!"</span>, string_reverse!
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- string[address, length] &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rdi</span>, buffer$string_reverse!
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rcx</span>, [pointer$argument_stack - (<span style="color: #ae81ff;">1</span> * cell_size)]
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rsi</span>, [pointer$argument_stack - (<span style="color: #ae81ff;">2</span> * cell_size)]
   <span style="color: #a6e22e;">rep</span> <span style="color: #a6e22e;">movsb</span>

   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rcx</span>, [pointer$argument_stack - (<span style="color: #ae81ff;">1</span> * cell_size)]
   <span style="color: #a6e22e;">dec</span> <span style="color: #fd971f;">rdi</span> <span style="color: #FF8888;">;; cursor back into string in buffer$string_reverse!</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rsi</span>, [pointer$argument_stack - (<span style="color: #ae81ff;">2</span> * cell_size)]
<span style="color: #a6e22e;">.loop</span>:
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">al</span>, <span style="color: #66d9ef; font-weight: bold;">byte</span> [<span style="color: #fd971f;">rdi</span>]
   <span style="color: #a6e22e;">mov</span> <span style="color: #66d9ef; font-weight: bold;">byte</span> [<span style="color: #fd971f;">rsi</span>], <span style="color: #fd971f;">al</span>
   <span style="color: #a6e22e;">dec</span> <span style="color: #fd971f;">rdi</span>
   <span style="color: #a6e22e;">inc</span> <span style="color: #fd971f;">rsi</span>
   <span style="color: #a6e22e;">loop</span> .loop

   next

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org4044070" class="outline-3">
<h3 id="org4044070">string-reverse!&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></h3>
<div class="outline-text-3" id="text-org4044070">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =32bit, machine {

buffer$string_reverse! <span style="color: #f92672; font-weight: bold;">labeling</span>
   <span style="color: #66d9ef; font-weight: bold;">preserve</span> <span style="color: #ae81ff;">1024</span>


define_primitive_function <span style="color: #e6db74;">"string-reverse!"</span>, string_reverse!
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- string[address, length] &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [pointer$argument_stack]
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rdi</span>, buffer$string_reverse!
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rcx</span>, [<span style="color: #fd971f;">rbx</span> - (<span style="color: #ae81ff;">1</span> * cell_size)]
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rsi</span>, [<span style="color: #fd971f;">rbx</span> - (<span style="color: #ae81ff;">2</span> * cell_size)]
   <span style="color: #a6e22e;">rep</span> <span style="color: #a6e22e;">movsb</span>

   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rcx</span>, [<span style="color: #fd971f;">rbx</span> - (<span style="color: #ae81ff;">1</span> * cell_size)]
   <span style="color: #a6e22e;">dec</span> <span style="color: #fd971f;">rdi</span> <span style="color: #FF8888;">;; cursor back into string in buffer$string_reverse!</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rsi</span>, [<span style="color: #fd971f;">rbx</span> - (<span style="color: #ae81ff;">2</span> * cell_size)]
<span style="color: #a6e22e;">.loop</span>:
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">al</span>, <span style="color: #66d9ef; font-weight: bold;">byte</span> [<span style="color: #fd971f;">rdi</span>]
   <span style="color: #a6e22e;">mov</span> <span style="color: #66d9ef; font-weight: bold;">byte</span> [<span style="color: #fd971f;">rsi</span>], <span style="color: #fd971f;">al</span>
   <span style="color: #a6e22e;">dec</span> <span style="color: #fd971f;">rdi</span>
   <span style="color: #a6e22e;">inc</span> <span style="color: #fd971f;">rsi</span>
   <span style="color: #a6e22e;">loop</span> .loop

   next

}
</pre>
</div>
</div>
</div>

<div id="outline-container-orgd3f1316" class="outline-3">
<h3 id="orgd3f1316">one-byte-string?</h3>
<div class="outline-text-3" id="text-orgd3f1316">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"one-byte-string?"</span>, one_byte_string?
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length], byte -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> xxswapx
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>, one?, false?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">5</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop2, drop
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   false
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string__byte, equal?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">3</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   true
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> false
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orgf3bc476" class="outline-3">
<h3 id="orgf3bc476">zero-string?</h3>
<div class="outline-text-3" id="text-orgf3bc476">
<ul class="org-ul">
<li><p>"0" or "-0"</p><p>0 is special when compiling literal number</p><p>for we are using 0 as "end"</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"zero-string?"</span>, zero_string?
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2, <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #e6db74;">'0'</span>, one_byte_string?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop2, true
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string__byte, <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #e6db74;">'-'</span>, equal?, false?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop2, false
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string__byte_tail, <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #e6db74;">'0'</span>, one_byte_string?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orgc94e208" class="outline-3">
<h3 id="orgc94e208">digit-string?</h3>
<div class="outline-text-3" id="text-orgc94e208">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"digit-string?"</span>, digit_string?
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>, zero?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop2, true
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> over, get_byte, digit_byte?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   string__byte_tail
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">tail_call</span>, digit_string?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> drop2, false
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org8e895f3" class="outline-3">
<h3 id="org8e895f3">integer-string?</h3>
<div class="outline-text-3" id="text-org8e895f3">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"integer-string?"</span>, integer_string?
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>, zero?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop2, false
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2, <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #e6db74;">'-'</span>, one_byte_string?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop2, false
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2, string__byte, <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #e6db74;">'-'</span>, equal?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   string__byte_tail
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   digit_string?
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> digit_string?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org24fe7cc" class="outline-3">
<h3 id="org24fe7cc">digit-string-&gt;number</h3>
<div class="outline-text-3" id="text-org24fe7cc">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">sum$digit_string_to_number</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #ae81ff;">0</span>

<span style="color: #a6e22e;">counter$digit_string_to_number</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #ae81ff;">0</span>

define_function <span style="color: #e6db74;">"digit-string-&gt;number"</span>, digit_string_to_number
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- integer &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> zero, <span style="color: #f92672; font-weight: bold;">literal</span>, sum$digit_string_to_number, set
   <span style="color: #66d9ef; font-weight: bold;">xx</span> zero, <span style="color: #f92672; font-weight: bold;">literal</span>, counter$digit_string_to_number, set

   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2, string_reverse!
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   help__digit_string_to_number
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string_reverse!, drop2

   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, sum$digit_string_to_number
   <span style="color: #66d9ef; font-weight: bold;">xx</span> get
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>

define_function <span style="color: #e6db74;">"help,digit-string-&gt;number"</span>, help__digit_string_to_number
   <span style="color: #FF8888;">;; &lt;&lt; reversed-string[address, length] -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>, zero?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">3</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop2
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>

   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2, string__byte, digit_byte_to_number
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">10</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, counter$digit_string_to_number, get
   <span style="color: #66d9ef; font-weight: bold;">xx</span>     one
   <span style="color: #66d9ef; font-weight: bold;">xx</span>     <span style="color: #f92672; font-weight: bold;">literal</span>, counter$digit_string_to_number
   <span style="color: #66d9ef; font-weight: bold;">xx</span>     add_set
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   power
   <span style="color: #66d9ef; font-weight: bold;">xx</span> multiple

   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, sum$digit_string_to_number
   <span style="color: #66d9ef; font-weight: bold;">xx</span> add_set

   <span style="color: #66d9ef; font-weight: bold;">xx</span> string__byte_tail
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">tail_call</span>, help__digit_string_to_number
</pre>
</div>
</div>
</div>

<div id="outline-container-orge161bc3" class="outline-3">
<h3 id="orge161bc3">string-&gt;integer</h3>
<div class="outline-text-3" id="text-orge161bc3">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"string-&gt;integer"</span>, string_to_integer
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- integer &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2, string__byte, <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #e6db74;">'-'</span>, equal?, false?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">3</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   digit_string_to_number
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string__byte_tail
   <span style="color: #66d9ef; font-weight: bold;">xx</span> digit_string_to_number
   <span style="color: #66d9ef; font-weight: bold;">xx</span> negate
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>


<div id="outline-container-org7a74f3b" class="outline-3">
<h3 id="org7a74f3b">string:find-byte</h3>
<div class="outline-text-3" id="text-org7a74f3b">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"string:find-byte"</span>, string__find_byte
  <span style="color: #FF8888;">;; &lt;&lt; string[address, length], byte</span>
  <span style="color: #FF8888;">;;    -- address, true</span>
  <span style="color: #FF8888;">;;    -- false &gt;&gt;</span>
  <span style="color: #66d9ef; font-weight: bold;">xx</span> over, zero?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">5</span>
  <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop, drop2
  <span style="color: #66d9ef; font-weight: bold;">xx</span>   false
  <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
  <span style="color: #66d9ef; font-weight: bold;">xx</span> xoverxx, get_byte
  <span style="color: #66d9ef; font-weight: bold;">xx</span> over, equal?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
  <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop2
  <span style="color: #66d9ef; font-weight: bold;">xx</span>   true
  <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
  <span style="color: #66d9ef; font-weight: bold;">xx</span> xxswapx
  <span style="color: #66d9ef; font-weight: bold;">xx</span> string__byte_tail
  <span style="color: #66d9ef; font-weight: bold;">xx</span> xswapxx
  <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">tail_call</span>, string__find_byte
</pre>
</div>
</div>
</div>

<div id="outline-container-org1dc900c" class="outline-3">
<h3 id="org1dc900c"><span class="done test">test</span> </h3>
<div class="outline-text-3" id="text-org1dc900c">
<div class="org-src-container">

<pre class="src src-cicada-nymph"><span style="color: #ffff00; font-weight: bold;">:</span> <span style="color: #ef5939; font-weight: bold;">XIE</span> Yuheng <span style="color: #ffff00; font-weight: bold;">;</span>
<span style="color: #fd971f; font-weight: bold;">32</span> <span style="color: #ffffff; font-weight: bold;">string:</span>find-byte . <span style="color: #FF8888;">&lt;&lt; 1 &gt;&gt;</span>
get-byte . <span style="color: #FF8888;">&lt;&lt; 32 &gt;&gt;</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orgfc92b03" class="outline-3">
<h3 id="orgfc92b03">string-end,byte</h3>
<div class="outline-text-3" id="text-orgfc92b03">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"string-end,byte"</span>, string_end__byte
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- byte &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> addition, sub1, get_byte
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>


<div id="outline-container-org6fc80bb" class="outline-3">
<h3 id="org6fc80bb"><span class="todo note">note</span> </h3>
<div class="outline-text-3" id="text-org6fc80bb">
<ul class="org-ul">
<li><p>one should use string:space? to make sure</p><p>that the string is not space-string</p><p>before calling the following functions</p></li></ul>
</div>
</div>

<div id="outline-container-orgfb1ed7a" class="outline-3">
<h3 id="orgfb1ed7a">string:space?</h3>
<div class="outline-text-3" id="text-orgfb1ed7a">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"string:space?"</span>, space_string?
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>, zero?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop2, true
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2, string__byte, space_byte?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   string__byte_tail
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">tail_call</span>, space_string?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> drop2, false
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org37f1f47" class="outline-3">
<h3 id="org37f1f47">string:word-begin</h3>
<div class="outline-text-3" id="text-org37f1f47">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"string:word-begin"</span>, string__word_begin
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- string[address, length] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>, zero?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">2</span>
   <span style="color: #FF8888;">;;   no error handling</span>
   <span style="color: #FF8888;">;;   the same empty-string is returned</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string__byte, space_byte?, false?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">2</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string__byte_tail
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">tail_call</span>, string__word_begin
</pre>
</div>
</div>
</div>

<div id="outline-container-org936a7b7" class="outline-3">
<h3 id="org936a7b7">string:word-end</h3>
<div class="outline-text-3" id="text-org936a7b7">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"string:word-end,loop"</span>, string__word_end__loop
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- string[address, length] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>, zero?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">2</span>
   <span style="color: #FF8888;">;;   no error handling</span>
   <span style="color: #FF8888;">;;   the current empty-string is returned</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string__byte, space_byte?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">2</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string__byte, bar_ket_byte?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">2</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string__byte_tail
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">tail_call</span>, string__word_end__loop

define_function <span style="color: #e6db74;">"string:word-end"</span>, string__word_end
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- string[address, length] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>, zero?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">2</span>
   <span style="color: #FF8888;">;;   no error handling</span>
   <span style="color: #FF8888;">;;   the same empty-string is returned</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string__byte, bar_ket_byte?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">3</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   string__byte_tail
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string__word_end__loop
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orgb45825b" class="outline-3">
<h3 id="orgb45825b">string:word</h3>
<div class="outline-text-3" id="text-orgb45825b">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"string:word"</span>, string__word
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- word[address, length] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string__word_begin
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2, string__word_end
   <span style="color: #66d9ef; font-weight: bold;">xx</span> swap, drop
   <span style="color: #66d9ef; font-weight: bold;">xx</span> subtraction
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org53a871f" class="outline-3">
<h3 id="org53a871f">string:word-tail</h3>
<div class="outline-text-3" id="text-org53a871f">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"string:word-tail"</span>, string__word_tail
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- string[address, length] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string__word_begin
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string__word_end
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>
</div>


<div id="outline-container-org530af3b" class="outline-2">
<h2 id="org530af3b">write number</h2>
<div class="outline-text-2" id="text-org530af3b">
</div><div id="outline-container-orgb5226b5" class="outline-3">
<h3 id="orgb5226b5">write-number</h3>
<div class="outline-text-3" id="text-orgb5226b5">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #FF8888;">;; 2 ^ 64 = 18446744073709551616</span>
<span style="color: #FF8888;">;; which is of length 20</span>
<span style="color: #FF8888;">;; so</span>
<span style="color: #FF8888;">;; I use 32 to align to 16</span>

buffer$write_number <span style="color: #f92672; font-weight: bold;">labeling</span>
   <span style="color: #66d9ef; font-weight: bold;">preserve</span> <span style="color: #ae81ff;">32</span>

<span style="color: #a6e22e;">counter$write_number</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #ae81ff;">0</span>

define_function <span style="color: #e6db74;">"write-number"</span>, write_number
   <span style="color: #FF8888;">;; &lt;&lt; number -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> write_number__fill_buffer
   <span style="color: #66d9ef; font-weight: bold;">xx</span> write_string
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>

define_function <span style="color: #e6db74;">"write-number,fill-buffer"</span>, write_number__fill_buffer
   <span style="color: #FF8888;">;; &lt;&lt; number -- string[address, length] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> zero
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, counter$write_number, set

   <span style="color: #66d9ef; font-weight: bold;">xx</span> write_number__loop

   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, buffer$write_number
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, counter$write_number, get
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string_reverse!
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>


define_function <span style="color: #e6db74;">"write-number,loop"</span>, write_number__loop
   <span style="color: #FF8888;">;; &lt;&lt; rest-number -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">10</span>, divmod

   <span style="color: #66d9ef; font-weight: bold;">xx</span> number_to_digit_byte
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, buffer$write_number
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, counter$write_number, get
   <span style="color: #66d9ef; font-weight: bold;">xx</span> addition
   <span style="color: #66d9ef; font-weight: bold;">xx</span> set_byte

   <span style="color: #66d9ef; font-weight: bold;">xx</span> one
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, counter$write_number
   <span style="color: #66d9ef; font-weight: bold;">xx</span> add_set

   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>, zero?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">3</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">tail_call</span>, write_number__loop
</pre>
</div>
</div>
</div>

<div id="outline-container-org9dea4d7" class="outline-3">
<h3 id="org9dea4d7">write-integer</h3>
<div class="outline-text-3" id="text-org9dea4d7">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"write-integer"</span>, write_integer
   <span style="color: #FF8888;">;; &lt;&lt; integer -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>, negative?, false?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">3</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   write_number
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #e6db74;">'-'</span>, write_byte
   <span style="color: #66d9ef; font-weight: bold;">xx</span> negate
   <span style="color: #66d9ef; font-weight: bold;">xx</span> write_number
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org7fc156b" class="outline-3">
<h3 id="org7fc156b">pretty_write_integer</h3>
<div class="outline-text-3" id="text-org7fc156b">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"pretty-write-integer"</span>, pretty_write_integer
   <span style="color: #FF8888;">;; &lt;&lt; integer -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> write_integer
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">32</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> write_byte
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>

define_function <span style="color: #e6db74;">"."</span>, ALIAS__pretty_write_integer
   <span style="color: #FF8888;">;; &lt;&lt; integer -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> pretty_write_integer
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-org2305b22" class="outline-2">
<h2 id="org2305b22">word</h2>
<div class="outline-text-2" id="text-org2305b22">
</div><div id="outline-container-org3d4965e" class="outline-3">
<h3 id="org3d4965e"><span class="todo note">note</span> io about word</h3>
<div class="outline-text-3" id="text-org3d4965e">
<ul class="org-ul">
<li><p>words are separated by spaces</p></li>
<li><p>a bar-ket is a word</p><p>even when there are no spaces around it</p></li></ul>
</div>
</div>

<div id="outline-container-org3a23795" class="outline-3">
<h3 id="org3a23795"><span class="todo note">note</span> bar-ket</h3>
<div class="outline-text-3" id="text-org3a23795">
<ul class="org-ul">
<li><p>(read-word) is not implemented by (read-byte)</p><p>instead it is implemented directly by side-effect on reading-stack</p><p>[just like (read-byte)]</p><p>thus</p><p>we can implement bar-ket as word easily</p><p>and nothing like un-read is needed</p><p>and</p><p>it is (string:word) and (string:word-tail)</p><p>these two functions are maintaining the "bar-ket as word" feature</p></li>
<li><p>otherwise</p><p>the implementation of (eval-string) will meet problems</p></li></ul>
</div>
</div>

<div id="outline-container-org6b276da" class="outline-3">
<h3 id="org6b276da">memory allocation</h3>
<div class="outline-text-3" id="text-org6b276da">
<div class="org-src-container">

<pre class="src src-fasm">max_word_length = <span style="color: #ae81ff;">512</span>

buffer$read_word <span style="color: #f92672; font-weight: bold;">labeling</span>
   <span style="color: #66d9ef; font-weight: bold;">preserve</span> max_word_length
</pre>
</div>
</div>
</div>

<div id="outline-container-org31bc39d" class="outline-3">
<h3 id="org31bc39d">read-word-&gt;buffer</h3>
<div class="outline-text-3" id="text-org31bc39d">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"read-word-&gt;buffer"</span>, read_word_to_buffer
   <span style="color: #FF8888;">;; &lt;&lt; buffer -- word[address, length] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> pop_reading_stack
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2, space_string?, CICADA__not, <span style="color: #f92672; font-weight: bold;">false?branch</span>, (.bad_tos-$)/cell_size
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   dup2, string__word_tail, push_reading_stack
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   string__word
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   xoverxx, xxoverx
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   xswapxx
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   string_to_buffer!
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   swap, drop
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
<span style="color: #a6e22e;">.bad_tos</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> reading_stack_empty?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, (.not_empty-$)/cell_size
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop2
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, buffer$reading
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, max_input_length
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   read_line_from_stdin
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">dup</span>, positive?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, (.read_error-$)/cell_size
   <span style="color: #66d9ef; font-weight: bold;">xx</span>     <span style="color: #f92672; font-weight: bold;">literal</span>, buffer$reading
   <span style="color: #66d9ef; font-weight: bold;">xx</span>     swap
   <span style="color: #66d9ef; font-weight: bold;">xx</span>     push_reading_stack
   <span style="color: #66d9ef; font-weight: bold;">xx</span>     <span style="color: #f92672; font-weight: bold;">tail_call</span>, read_word_to_buffer
<span style="color: #a6e22e;">.read_error</span>:
   <span style="color: #FF8888;">;;   ignore &lt;end-of-file&gt;</span>
   <span style="color: #FF8888;">;;   ignore reading error</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, buffer$reading
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">0</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   push_reading_stack
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">tail_call</span>, read_word_to_buffer
<span style="color: #a6e22e;">.not_empty</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, error$read_word_to_buffer
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, length$read_word_to_buffer
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   write_string
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, replace$reading
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">1024</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   read_line_from_stdin
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, replace$reading
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   swap
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   push_reading_stack
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">tail_call</span>, read_word_to_buffer

<span style="color: #a6e22e;">error$read_word_to_buffer</span>:
   <span style="color: #66d9ef; font-weight: bold;">db</span> <span style="color: #e6db74;">"* (read-word-&gt;buffer) meets empty-string in reading-stack"</span>, <span style="color: #ae81ff;">10</span>
   <span style="color: #66d9ef; font-weight: bold;">db</span> <span style="color: #e6db74;">"  and this empty-stack is not at the bottom of the reading-stack"</span>, <span style="color: #ae81ff;">10</span>
   <span style="color: #66d9ef; font-weight: bold;">db</span> <span style="color: #e6db74;">"  you can type a line to replace this empty string"</span>, <span style="color: #ae81ff;">10</span>
<span style="color: #a6e22e;">.end</span>:
length$read_word_to_buffer = (.end - error$read_word_to_buffer)
</pre>
</div>
</div>
</div>

<div id="outline-container-org4a6ee9b" class="outline-3">
<h3 id="org4a6ee9b">read-word</h3>
<div class="outline-text-3" id="text-org4a6ee9b">
<ul class="org-ul">
<li><p>read-word will override the word readed before</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"read-word"</span>, read_word
   <span style="color: #FF8888;">;; &lt;&lt; -- word[address of buffer$read_word, length] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, buffer$read_word, read_word_to_buffer
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-org235633e" class="outline-2">
<h2 id="org235633e">link</h2>
<div class="outline-text-2" id="text-org235633e">
</div><div id="outline-container-org466f0a1" class="outline-3">
<h3 id="org466f0a1">last-link?</h3>
<div class="outline-text-3" id="text-org466f0a1">
<ul class="org-ul">
<li><p>fatal error on zero</p></li>
<li><p>the last-link is not zero</p><p>but is a link of which the link field is zero</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"last-link?"</span>, last_link?
   <span style="color: #FF8888;">;; &lt;&lt; link -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> get, zero?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org2cdf0f1" class="outline-3">
<h3 id="org2cdf0f1">link-&gt;next-link</h3>
<div class="outline-text-3" id="text-org2cdf0f1">
<ul class="org-ul">
<li><p>fatal error on zero</p></li>
<li><p>the test of zero? is for less core dump</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"link-&gt;next-link"</span>, link_to_next_link
  <span style="color: #FF8888;">;; &lt;&lt; link -- next-link &gt;&gt;</span>
  <span style="color: #66d9ef; font-weight: bold;">xx</span> get
  <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org485f6c" class="outline-3">
<h3 id="org485f6c">link-&gt;name-string</h3>
<div class="outline-text-3" id="text-org485f6c">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"link-&gt;name-string"</span>, link_to_name_string
   <span style="color: #FF8888;">;; &lt;&lt; link -- string[address, length] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, offset__link$string_address, addition
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">2</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> n_get
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orgad42f93" class="outline-3">
<h3 id="orgad42f93">link-&gt;jo</h3>
<div class="outline-text-3" id="text-orgad42f93">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"link-&gt;jo"</span>, link_to_jo
   <span style="color: #FF8888;">;; &lt;&lt; link -- jo &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, offset__link$jo, addition, get
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org4354d3" class="outline-3">
<h3 id="org4354d3">link,set-jo</h3>
<div class="outline-text-3" id="text-org4354d3">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"link,set-jo"</span>, link__set_jo
   <span style="color: #FF8888;">;; &lt;&lt; jo, link -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, offset__link$jo, addition
   <span style="color: #66d9ef; font-weight: bold;">xx</span> set
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orgdf8e244" class="outline-3">
<h3 id="orgdf8e244"><b>link</b></h3>
<div class="outline-text-3" id="text-orgdf8e244">
<ul class="org-ul">
<li><p>a link is the first jo in the link</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">define_variable <span style="color: #e6db74;">"*link*"</span>, V__link
   <span style="color: #66d9ef; font-weight: bold;">xx</span> the_last_link_in_assembly_code
</pre>
</div>
</div>
</div>

<div id="outline-container-orge365ca8" class="outline-3">
<h3 id="orge365ca8"><span class="todo note">note</span> about find</h3>
<div class="outline-text-3" id="text-orge365ca8">
<ul class="org-ul">
<li><p>a function whoes name is prefixed by "find"</p><p>maybe fail to find</p><p>and maybe returns a signal</p><p>to inform the function who calls it</p></li></ul>
</div>
</div>

<div id="outline-container-org99a163c" class="outline-3">
<h3 id="org99a163c"><span class="todo _">記</span> 遍歷鏈表的方式</h3>
<div class="outline-text-3" id="text-org99a163c">
<ul class="org-ul">
<li><p>循環進行的方式是</p><p><ol class="org-ol"></p><p><li>保證循環開始時 所得到的 jo 不是最後一個</li></p><p><li>處理這個 jo</li></p><p><li>看看這個 jo 是否是最後一個</p><p><ul class="org-ul"></p><p><li><p>如果是</p><p>退出</p></li></p><p><li><p>如果不是</p><p>取下一個 jo 以循環</p></li></ul></li></ol></p></li></ul>
</div>
</div>

<div id="outline-container-orga76c9d" class="outline-3">
<h3 id="orga76c9d">find-link</h3>
<div class="outline-text-3" id="text-orga76c9d">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"find-link"</span>, find_link
   <span style="color: #FF8888;">;; &lt;&lt; word[address, length], link</span>
   <span style="color: #FF8888;">;;    -- link, true</span>
   <span style="color: #FF8888;">;;    -- false &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> xxtuckx
   <span style="color: #66d9ef; font-weight: bold;">xx</span> link_to_name_string, xxoverxx

   <span style="color: #FF8888;">;; xx xxoverxx</span>
   <span style="color: #FF8888;">;; xx xxoverxx</span>
   <span style="color: #FF8888;">;; xx write_string, literal, 32, write_byte</span>
   <span style="color: #FF8888;">;; xx write_string, literal, 10, write_byte</span>

   <span style="color: #66d9ef; font-weight: bold;">xx</span> string_equal?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop2, true
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> xswapxx
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>, last_link?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">5</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop, drop2
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   false
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> link_to_next_link
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">tail_call</span>, find_link
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-org9ed96e4" class="outline-2">
<h2 id="org9ed96e4">basic-REPL</h2>
<div class="outline-text-2" id="text-org9ed96e4">
</div><div id="outline-container-org78d5cd7" class="outline-3">
<h3 id="org78d5cd7">word-interpreter</h3>
<div class="outline-text-3" id="text-org78d5cd7">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"word-interpreter"</span>, word_interpreter
   <span style="color: #FF8888;">;; &lt;&lt; word[address, length] -- unknown &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2, integer_string?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">3</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   string_to_integer
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #FF8888;">;; maybe more</span>

   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2 <span style="color: #FF8888;">;; for to report undefined word</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__link
   <span style="color: #66d9ef; font-weight: bold;">xx</span> find_link, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">6</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   xxswapx, drop2
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   link_to_jo, apply
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>

   <span style="color: #66d9ef; font-weight: bold;">xx</span> write_undefined_word_report__for_word_interpreter
   <span style="color: #66d9ef; font-weight: bold;">xx</span> write_string
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">10</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> write_byte
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>


define_function <span style="color: #e6db74;">"write-undefined-word-report,for-word-interpreter"</span>, write_undefined_word_report__for_word_interpreter
   <span style="color: #FF8888;">;; &lt;&lt; -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, string$undefined_word_report__for_word_interpreter
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, length$undefined_word_report__for_word_interpreter
   <span style="color: #66d9ef; font-weight: bold;">xx</span> write_string
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>

<span style="color: #a6e22e;">string$undefined_word_report__for_word_interpreter</span>:
   <span style="color: #66d9ef; font-weight: bold;">db</span> <span style="color: #e6db74;">"* (word-interpreter) meets undefined word : "</span>
<span style="color: #a6e22e;">.end</span>:
length$undefined_word_report__for_word_interpreter = (.end - string$undefined_word_report__for_word_interpreter)
</pre>
</div>
</div>
</div>

<div id="outline-container-orgfe4f120" class="outline-3">
<h3 id="orgfe4f120">basic-REPL</h3>
<div class="outline-text-3" id="text-orgfe4f120">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"basic-REPL"</span>, basic_REPL
   <span style="color: #FF8888;">;; &lt;&lt; unknown -- unknown &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> read_word
   <span style="color: #66d9ef; font-weight: bold;">xx</span> word_interpreter
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">tail_call</span>, basic_REPL
</pre>
</div>
</div>
</div>
</div>


<div id="outline-container-org2e7af8b" class="outline-2">
<h2 id="org2e7af8b">colon semicolon</h2>
<div class="outline-text-2" id="text-org2e7af8b">
</div><div id="outline-container-org9a75f2c" class="outline-3">
<h3 id="org9a75f2c"><span class="todo note">note</span> </h3>
<div class="outline-text-3" id="text-org9a75f2c">
<ul class="org-ul">
<li><p>from the aesthetics point of view</p><p>I do NOT think which of the following is better then the other</p><p>but I choose the second one</p></li>
<li><p><p></p><p>first</p><p></p></p><p><div class="org-src-container"></p><p></p><p><pre class="src src-cicada-nymph">define-function factorial</p><p>  <span style="color: #FF8888;">&lt;&lt; n -- n! &gt;&gt;</span></p><p>  dup <span style="color: #ffffff; font-weight: bold;">one?</span> <span style="color: #f92672; font-weight: bold;">if</span></p><p>    <span style="color: #00ffff; font-weight: bold;">end</span></p><p>  <span style="color: #f92672; font-weight: bold;">then</span></p><p>  dup sub1 factorial mul</p><p>  <span style="color: #00ffff; font-weight: bold;">end</span></p><p><span style="color: #00ffff; font-weight: bold;">end</span></p><p></pre></p><p></div></p></li>
<li><p><p></p><p>second</p><p></p></p><p><div class="org-src-container"></p><p></p><p><pre class="src src-cicada-nymph"><span style="color: #ffff00; font-weight: bold;">:</span> <span style="color: #ef5939; font-weight: bold;">factorial</span></p><p>  <span style="color: #FF8888;">&lt;&lt; n -- n! &gt;&gt;</span></p><p>  dup <span style="color: #ffffff; font-weight: bold;">one?</span> <span style="color: #f92672; font-weight: bold;">if</span></p><p>    <span style="color: #00ffff; font-weight: bold;">end</span></p><p>  <span style="color: #f92672; font-weight: bold;">then</span></p><p>  dup sub1 factorial mul</p><p>  <span style="color: #00ffff; font-weight: bold;">end</span></p><p><span style="color: #ffff00; font-weight: bold;">;</span> <span style="color: #ae81ff; font-weight: bold;">define-function</span></p><p></pre></p><p></div></p></li></ul>
</div>
</div>

<div id="outline-container-orge3f9a9d" class="outline-3">
<h3 id="orge3f9a9d">[colon|semicolon]-string?</h3>
<div class="outline-text-3" id="text-orge3f9a9d">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"colon-string?"</span>, colon_string?
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #e6db74;">':'</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> one_byte_string?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>

define_function <span style="color: #e6db74;">"semicolon-string?"</span>, semicolon_string?
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #e6db74;">';'</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> one_byte_string?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orgb866435" class="outline-3">
<h3 id="orgb866435">comment-[begin|end]-string?</h3>
<div class="outline-text-3" id="text-orgb866435">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">string$comment_begin</span>:
   <span style="color: #66d9ef; font-weight: bold;">db</span> <span style="color: #e6db74;">"&lt;&lt;"</span>

define_function <span style="color: #e6db74;">"comment-begin-string?"</span>, comment_begin_string?
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, string$comment_begin
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">2</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string_equal?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>


<span style="color: #a6e22e;">string$comment_end</span>:
   <span style="color: #66d9ef; font-weight: bold;">db</span> <span style="color: #e6db74;">"&gt;&gt;"</span>

define_function <span style="color: #e6db74;">"comment-end-string?"</span>, comment_end_string?
   <span style="color: #FF8888;">;; &lt;&lt; -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, string$comment_end
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">2</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string_equal?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orgbbdb82e" class="outline-3">
<h3 id="orgbbdb82e">colon &amp; semicolon</h3>
<div class="outline-text-3" id="text-orgbbdb82e">
<ul class="org-ul">
<li><p>nested : ; is NOT allow</p><p>and no error check for it</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">buffer$colon <span style="color: #f92672; font-weight: bold;">labeling</span>
   <span style="color: #66d9ef; font-weight: bold;">preserve</span> <span style="color: #ae81ff;">1024</span> * <span style="color: #ae81ff;">1024</span>

<span style="color: #a6e22e;">cursor$colon</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #ae81ff;">0</span>

<span style="color: #a6e22e;">length$colon</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #ae81ff;">0</span>

define_function <span style="color: #e6db74;">":"</span>, colon
   <span style="color: #FF8888;">;; &lt;&lt; -- string[address of buffer$colon, length] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, buffer$colon
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, cursor$colon, set
   <span style="color: #66d9ef; font-weight: bold;">xx</span> colon__loop
   <span style="color: #FF8888;">;; address</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, buffer$colon
   <span style="color: #FF8888;">;; length</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, cursor$colon, get
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, buffer$colon
   <span style="color: #66d9ef; font-weight: bold;">xx</span> subtraction
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>, <span style="color: #f92672; font-weight: bold;">literal</span>, length$colon, set
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>

define_function <span style="color: #e6db74;">"colon,loop"</span>, colon__loop
   <span style="color: #FF8888;">;; &lt;&lt; -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> read_byte
   <span style="color: #66d9ef; font-weight: bold;">xx</span> colon__set_byte
   <span style="color: #66d9ef; font-weight: bold;">xx</span> colon__meet_end?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">7</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">3</span> <span style="color: #FF8888;">;; for the string " ; "</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, cursor$colon
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   sub_set
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">tail_call</span>, colon__loop

define_function <span style="color: #e6db74;">"colon,set-byte"</span>, colon__set_byte
   <span style="color: #FF8888;">;; &lt;&lt; byte -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, cursor$colon, get
   <span style="color: #66d9ef; font-weight: bold;">xx</span> set_byte
   <span style="color: #66d9ef; font-weight: bold;">xx</span> one
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, cursor$colon
   <span style="color: #66d9ef; font-weight: bold;">xx</span> add_set
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>

define_function <span style="color: #e6db74;">"colon,meet-end?"</span>, colon__meet_end?
   <span style="color: #FF8888;">;; &lt;&lt; -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, cursor$colon, get
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">3</span>, subtraction
   <span style="color: #66d9ef; font-weight: bold;">xx</span> get_byte, space_byte?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> false?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">3</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   false
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, cursor$colon, get
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">2</span>, subtraction
   <span style="color: #66d9ef; font-weight: bold;">xx</span> get_byte, <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #e6db74;">';'</span>, equal?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> false?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">3</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   false
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, cursor$colon, get
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">1</span>, subtraction
   <span style="color: #66d9ef; font-weight: bold;">xx</span> get_byte, space_byte?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> false?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">3</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   false
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> true
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orgd66f701" class="outline-3">
<h3 id="orgd66f701">ignore-comment</h3>
<div class="outline-text-3" id="text-orgd66f701">
<ul class="org-ul">
<li><p>this function is for basic-REPL</p><p>but it is reused by colon</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"&lt;&lt;"</span>, ignore_comment
   <span style="color: #FF8888;">;; &lt;&lt; -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> read_word
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2, comment_begin_string?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">5</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop2
   <span style="color: #66d9ef; font-weight: bold;">xx</span>     ignore_comment <span style="color: #FF8888;">;; for the new nested-comment</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">tail_call</span>, ignore_comment <span style="color: #FF8888;">;; for the rest-comment</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2, comment_end_string?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">3</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop2
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> drop2
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">tail_call</span>, ignore_comment
</pre>
</div>
</div>
</div>

<div id="outline-container-org4c0c4f4" class="outline-3">
<h3 id="org4c0c4f4"><span class="done test">test</span> </h3>
<div class="outline-text-3" id="text-org4c0c4f4">
<div class="org-src-container">

<pre class="src src-cicada-nymph"><span style="color: #fd971f; font-weight: bold;">1</span> <span style="color: #FF8888;">&lt;&lt; 989 &gt;&gt;</span> <span style="color: #fd971f; font-weight: bold;">64</span> add .
<span style="color: #FF8888;">&lt;&lt; 65 &gt;&gt;</span>

<span style="color: #ffff00; font-weight: bold;">:</span> <span style="color: #ef5939; font-weight: bold;">kkk</span> <span style="color: #FF8888;">&lt;&lt; 989 &lt;&lt; 989 &gt;&gt;</span> &gt;&gt; <span style="color: #ffff00; font-weight: bold;">;</span> .s
<span style="color: #FF8888;">&lt;&lt; kkk &gt;&gt;</span>
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-org6f7d4a2" class="outline-2">
<h2 id="org6f7d4a2">jojo-area</h2>
<div class="outline-text-2" id="text-org6f7d4a2">
</div><div id="outline-container-orgd662b74" class="outline-3">
<h3 id="orgd662b74"><span class="todo note">note</span> </h3>
<div class="outline-text-3" id="text-orgd662b74">
<ul class="org-ul">
<li><p>you can see how the naming convention is used</p><p>for functions that create structured data into memory</p></li></ul>
</div>
</div>

<div id="outline-container-org90ce64" class="outline-3">
<h3 id="org90ce64">memory allocation</h3>
<div class="outline-text-3" id="text-org90ce64">
<div class="org-src-container">

<pre class="src src-fasm">size$jojo_area = <span style="color: #ae81ff;">1024</span> * <span style="color: #ae81ff;">1024</span> * cell_size

define_variable <span style="color: #e6db74;">"*jojo-area*"</span>, V__jojo_area
  <span style="color: #66d9ef; font-weight: bold;">xx</span> address$jojo_area

define_variable <span style="color: #e6db74;">"*jojo-area,size*"</span>, V__jojo_area__size
  <span style="color: #66d9ef; font-weight: bold;">xx</span> size$jojo_area


address$jojo_area <span style="color: #f92672; font-weight: bold;">labeling</span>
   <span style="color: #66d9ef; font-weight: bold;">preserve</span> size$jojo_area

define_variable <span style="color: #e6db74;">"*jojo-area,current-free-address*"</span>, V__jojo_area__current_free_address
   <span style="color: #66d9ef; font-weight: bold;">xx</span> address$jojo_area
</pre>
</div>
</div>
</div>

<div id="outline-container-orgc32cd41" class="outline-3">
<h3 id="orgc32cd41">jojo-area,stay</h3>
<div class="outline-text-3" id="text-orgc32cd41">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"jojo-area,stay"</span>, jojo_area__stay
   <span style="color: #FF8888;">;; &lt;&lt; number -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__jojo_area__current_free_address
   <span style="color: #66d9ef; font-weight: bold;">xx</span> set
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, cell_size
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">address</span>, V__jojo_area__current_free_address
   <span style="color: #66d9ef; font-weight: bold;">xx</span> add_set
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-org947123" class="outline-2">
<h2 id="org947123">make-link</h2>
<div class="outline-text-2" id="text-org947123">
<ul class="org-ul">
<li><p><p></p><p>link as data-structure</p><p></p></p><p><table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"></p><p></p><p></p><p><colgroup></p><p><col  class="org-left" /></p><p></p><p><col  class="org-left" /></p><p></colgroup></p><p><thead></p><p><tr></p><p><th scope="col" class="org-left">link</th></p><p><th scope="col" class="org-left">next-link</th></p><p></tr></p><p></thead></p><p><tbody></p><p><tr></p><p><td class="org-left">&#xa0;</td></p><p><td class="org-left">jo</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">&#xa0;</td></p><p><td class="org-left">string-address</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">&#xa0;</td></p><p><td class="org-left">string-length</td></p><p></tr></p><p></tbody></p><p></table></p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"make-link"</span>, make_link
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length], next-link, jo -- link &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__jojo_area__current_free_address
   <span style="color: #66d9ef; font-weight: bold;">xx</span> xxxxswapx
   <span style="color: #66d9ef; font-weight: bold;">xx</span> swap
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   jojo_area__stay
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   jojo_area__stay
   <span style="color: #66d9ef; font-weight: bold;">xx</span> swap
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   jojo_area__stay
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   jojo_area__stay
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org3e68ae6" class="outline-2">
<h2 id="org3e68ae6">make-jo-head</h2>
<div class="outline-text-2" id="text-org3e68ae6">
<ul class="org-ul">
<li><p><p></p><p>jo as data-structure</p><p></p></p><p><table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"></p><p></p><p></p><p><colgroup></p><p><col  class="org-left" /></p><p></p><p><col  class="org-left" /></p><p></colgroup></p><p><thead></p><p><tr></p><p><th scope="col" class="org-left">&#xa0;</th></p><p><th scope="col" class="org-left">length</th></p><p></tr></p><p></thead></p><p><tbody></p><p><tr></p><p><td class="org-left">jo</td></p><p><td class="org-left">explainer</td></p><p></tr></p><p></tbody></p><p><tbody></p><p><tr></p><p><td class="org-left">&#xa0;</td></p><p><td class="org-left">body</td></p><p></tr></p><p></tbody></p><p></table></p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"make-jo-head"</span>, make_jo_head
   <span style="color: #FF8888;">;; &lt;&lt; explainer, length -- jo &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   jojo_area__stay
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__jojo_area__current_free_address
   <span style="color: #66d9ef; font-weight: bold;">xx</span> swap
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   jojo_area__stay
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orgbe79f82" class="outline-2">
<h2 id="orgbe79f82">syntax-stack</h2>
<div class="outline-text-2" id="text-orgbe79f82">
</div><div id="outline-container-orgdcf84cb" class="outline-3">
<h3 id="orgdcf84cb"><span class="todo _">記</span> </h3>
<div class="outline-text-3" id="text-orgdcf84cb">
<ul class="org-ul">
<li><p><b>syntax-stack</b> 轉換語境</p></li>
<li><p><b>syntax-rule-set:&#x2026;</b> 添加語法</p></li></ul>
</div>
</div>

<div id="outline-container-org80bd8fb" class="outline-3">
<h3 id="org80bd8fb">memory allocate</h3>
<div class="outline-text-3" id="text-org80bd8fb">
<div class="org-src-container">

<pre class="src src-fasm">   <span style="color: #66d9ef; font-weight: bold;">preserve</span> cell_size * <span style="color: #ae81ff;">64</span>
address$syntax_stack <span style="color: #f92672; font-weight: bold;">labeling</span>
   <span style="color: #66d9ef; font-weight: bold;">preserve</span> cell_size * <span style="color: #ae81ff;">1024</span>

define_variable <span style="color: #e6db74;">"syntax-stack:*address*"</span>, V__syntax_stack__address
   <span style="color: #66d9ef; font-weight: bold;">xx</span> address$syntax_stack

define_variable <span style="color: #e6db74;">"syntax-stack:*pointer*"</span>, V__syntax_stack__pointer
   <span style="color: #66d9ef; font-weight: bold;">xx</span> address$syntax_stack
</pre>
</div>
</div>
</div>

<div id="outline-container-orgf0262f5" class="outline-3">
<h3 id="orgf0262f5">push-syntax-stack</h3>
<div class="outline-text-3" id="text-orgf0262f5">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"push-syntax-stack"</span>, push_syntax_stack
   <span style="color: #FF8888;">;; &lt;&lt; syntax-set[address] -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__syntax_stack__pointer
   <span style="color: #66d9ef; font-weight: bold;">xx</span> set
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__cell_size
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">address</span>, V__syntax_stack__pointer
   <span style="color: #66d9ef; font-weight: bold;">xx</span> add_set
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org6b33a79" class="outline-3">
<h3 id="org6b33a79">pop-syntax-stack</h3>
<div class="outline-text-3" id="text-org6b33a79">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"pop-syntax-stack"</span>, pop_syntax_stack
   <span style="color: #FF8888;">;; &lt;&lt; -- syntax-set[address] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__cell_size
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">address</span>, V__syntax_stack__pointer
   <span style="color: #66d9ef; font-weight: bold;">xx</span> sub_set
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__syntax_stack__pointer, get
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orgfbe7dd0" class="outline-3">
<h3 id="orgfbe7dd0">tos-syntax-stack</h3>
<div class="outline-text-3" id="text-orgfbe7dd0">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"tos-syntax-stack"</span>, tos_syntax_stack
   <span style="color: #FF8888;">;; &lt;&lt; -- syntax-set[address] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__syntax_stack__pointer
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__cell_size
   <span style="color: #66d9ef; font-weight: bold;">xx</span> subtraction
   <span style="color: #66d9ef; font-weight: bold;">xx</span> get
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orgbfd3d16" class="outline-3">
<h3 id="orgbfd3d16">drop-syntax-stack</h3>
<div class="outline-text-3" id="text-orgbfd3d16">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"drop-syntax-stack"</span>, drop_syntax_stack
   <span style="color: #FF8888;">;; &lt;&lt; -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__cell_size
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">address</span>, V__syntax_stack__pointer
   <span style="color: #66d9ef; font-weight: bold;">xx</span> sub_set
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orgad8f2e7" class="outline-3">
<h3 id="orgad8f2e7">syntax-stack-empty?</h3>
<div class="outline-text-3" id="text-orgad8f2e7">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"syntax-stack-empty?"</span>, syntax_stack_empty?
   <span style="color: #FF8888;">;; &lt;&lt; -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__syntax_stack__pointer
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, address$syntax_stack
   <span style="color: #66d9ef; font-weight: bold;">xx</span> equal?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org20d6ed2" class="outline-3">
<h3 id="org20d6ed2">find-syntax</h3>
<div class="outline-text-3" id="text-org20d6ed2">
<ul class="org-ul">
<li><p><p></p><p>only search the first syntax-rule-set in syntax-stack</p><p>thus a switch of syntax will get you a clean syntax</p><p></p></p><p><div class="org-src-container"></p><p></p><p><pre class="src src-fasm">define_function <span style="color: #e6db74;">"find-syntax"</span>, find_syntax</p><p>   <span style="color: #FF8888;">;; &lt;&lt; word[address, length]</span></p><p>   <span style="color: #FF8888;">;;    -- function, true</span></p><p>   <span style="color: #FF8888;">;;    -- false &gt;&gt;</span></p><p>   <span style="color: #66d9ef; font-weight: bold;">xx</span> syntax_stack_empty?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span></p><p>   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop2</p><p>   <span style="color: #66d9ef; font-weight: bold;">xx</span>   false</p><p>   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span></p><p>   <span style="color: #66d9ef; font-weight: bold;">xx</span> tos_syntax_stack</p><p>   <span style="color: #66d9ef; font-weight: bold;">xx</span> syntax_rule_set__find</p><p>   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span></p><p></pre></p><p></div></p></li></ul>
</div>
</div>
</div>

<div id="outline-container-org5c361a6" class="outline-2">
<h2 id="org5c361a6">syntax-rule-set</h2>
<div class="outline-text-2" id="text-org5c361a6">
</div><div id="outline-container-org3396e3d" class="outline-3">
<h3 id="org3396e3d"><span class="todo _">記</span> 使用</h3>
<div class="outline-text-3" id="text-org3396e3d">
<ul class="org-ul">
<li><p>syntax-rule-set:jojo-compiler 是</p><p>語法謂詞 還有 語法函數 這種對子</p><p>所形成的有序集合</p><p>這樣就可以形成簡單的語境概念了</p></li>
<li><p>每個語境都有責任</p><p>在進入和退出時</p><p>維護好 syntax-rule-set:jojo-compiler</p></li>
<li><p><p></p><p>以 syntax 爲前綴的 function 的類型常常是</p><p></p></p><p><ol class="org-ol"></p><p><li>以 jojo-compiler 爲後綴時</p><p>&lt;&lt; jo, string[address, length], word[address, length]</p><p>&#x2013; jo, string[address, length] &gt;&gt;</li></p><p><li>在 REPL 中使用時又可以是</p><p>&lt;&lt; word[address, length] &#x2013; integer &gt;&gt;</li></ol></p><p><p></p><p>所以在使用時</p><p>一定要注意維護棧中的值的良好性</p><p></p></p></li></ul>
</div>
</div>

<div id="outline-container-orga360c3c" class="outline-3">
<h3 id="orga360c3c"><span class="todo note">note</span> border</h3>
<div class="outline-text-3" id="text-orga360c3c">
<ul class="org-ul">
<li><p>border is current-free-address of syntax-rule-set</p></li></ul>
</div>
</div>

<div id="outline-container-orgfd196c5" class="outline-3">
<h3 id="orgfd196c5"><span class="todo _">記</span> interface</h3>
<div class="outline-text-3" id="text-orgfd196c5">
<ul class="org-ul">
<li><p><p></p><p>structure</p><p></p></p><p><table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"></p><p></p><p></p><p><colgroup></p><p><col  class="org-left" /></p><p></p><p><col  class="org-left" /></p><p></colgroup></p><p><tbody></p><p><tr></p><p><td class="org-left">syntax-rule</td></p><p><td class="org-left">predicate</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">&#xa0;</td></p><p><td class="org-left">function</td></p><p></tr></p><p></tbody></p><p></table></p></li>
<li><p>on stack</p><p>&lt;&lt; syntax-rule[predicate, function] &gt;&gt;</p></li>
<li><p>set is an ordered set</p><p>its interface is as the following</p><p><ol class="org-ol"></p><p><li>(add-syntax-rule)</p><p>add a syntax-rule into syntax-rule-set</li></p><p><li>(sub-syntax-rule)</p><p>try to sub a syntax-rule from syntax-rule-set</p><p>once a time</p><p>if can not find the syntax-rule in the syntax-rule-set</p><p>do nothing</li></p><p><li>(find-syntax-rule)</p><p>find a function from a word</li></p><p><li>(list-syntax-rule)</li></ol></p></li></ul>
</div>
</div>

<div id="outline-container-org8b4e4c8" class="outline-3">
<h3 id="org8b4e4c8">syntax-rule:*unit*</h3>
<div class="outline-text-3" id="text-org8b4e4c8">
<div class="org-src-container">

<pre class="src src-fasm">define_variable <span style="color: #e6db74;">"syntax-rule:*unit*"</span>, V__syntax_rule__unit
   <span style="color: #66d9ef; font-weight: bold;">xx</span> (cell_size * <span style="color: #ae81ff;">2</span>)
</pre>
</div>
</div>
</div>

<div id="outline-container-org3e88744" class="outline-3">
<h3 id="org3e88744">syntax-rule:get-predicate</h3>
<div class="outline-text-3" id="text-org3e88744">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"syntax-rule:get-predicate"</span>, syntax_rule__get_predicate
   <span style="color: #FF8888;">;; &lt;&lt; syntax-rule[address] -- predicate &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> get
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orgec7cb95" class="outline-3">
<h3 id="orgec7cb95">syntax-rule:get-function</h3>
<div class="outline-text-3" id="text-orgec7cb95">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"syntax-rule:get-function"</span>, syntax_rule__get_function
   <span style="color: #FF8888;">;; &lt;&lt; syntax-rule[address] -- function &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__cell_size, addition
   <span style="color: #66d9ef; font-weight: bold;">xx</span> get
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org83a85ec" class="outline-3">
<h3 id="org83a85ec">syntax-rule:get</h3>
<div class="outline-text-3" id="text-org83a85ec">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"syntax-rule:get"</span>, syntax_rule__get
   <span style="color: #FF8888;">;; &lt;&lt; syntax-rule[address] -- syntax-rule[predicate, function] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__syntax_rule__unit, V__cell_size, division
   <span style="color: #66d9ef; font-weight: bold;">xx</span> n_get
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orgb090c98" class="outline-3">
<h3 id="orgb090c98">syntax-rule-set:get-border</h3>
<div class="outline-text-3" id="text-orgb090c98">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"syntax-rule-set:get-border"</span>, syntax_rule_set__get_border
   <span style="color: #FF8888;">;; &lt;&lt; syntax-rule-set -- border &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__cell_size, subtraction
   <span style="color: #66d9ef; font-weight: bold;">xx</span> get
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orgab651c0" class="outline-3">
<h3 id="orgab651c0">syntax-rule-set:set-border</h3>
<div class="outline-text-3" id="text-orgab651c0">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"syntax-rule-set:set-border"</span>, syntax_rule_set__set_border
   <span style="color: #FF8888;">;; &lt;&lt; border, syntax-rule-set -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__cell_size, subtraction
   <span style="color: #66d9ef; font-weight: bold;">xx</span> set
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org749d337" class="outline-3">
<h3 id="org749d337">syntax-rule:add</h3>
<div class="outline-text-3" id="text-org749d337">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"syntax-rule:add"</span>, syntax_rule__add
   <span style="color: #FF8888;">;; &lt;&lt; syntax-rule-set: syntax-rule[predicate, function] -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> xoverxx
   <span style="color: #66d9ef; font-weight: bold;">xx</span> syntax_rule_set__get_border
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">2</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> n_set
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> syntax_rule_set__get_border
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__cell_size, addition
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__cell_size, addition
   <span style="color: #66d9ef; font-weight: bold;">xx</span> swap
   <span style="color: #66d9ef; font-weight: bold;">xx</span> syntax_rule_set__set_border
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org701bbef" class="outline-3">
<h3 id="org701bbef">syntax-rule-set:find</h3>
<div class="outline-text-3" id="text-org701bbef">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">cursor$syntax_rule_set__find</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #ae81ff;">0</span>

define_function <span style="color: #e6db74;">"syntax-rule-set:find"</span>, syntax_rule_set__find
   <span style="color: #FF8888;">;; &lt;&lt; word[address, length], syntax-rule-set</span>
   <span style="color: #FF8888;">;;    -- function, true</span>
   <span style="color: #FF8888;">;;    -- false &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>, syntax_rule_set__get_border
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, cursor$syntax_rule_set__find, set
   <span style="color: #66d9ef; font-weight: bold;">xx</span> syntax_rule_set__find__loop
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>

define_function <span style="color: #e6db74;">"syntax-rule-set:find,loop"</span>, syntax_rule_set__find__loop
   <span style="color: #FF8888;">;; &lt;&lt; word[address, length], syntax-rule-set</span>
   <span style="color: #FF8888;">;;    -- function, true</span>
   <span style="color: #FF8888;">;;    -- false &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, cursor$syntax_rule_set__find, get
   <span style="color: #66d9ef; font-weight: bold;">xx</span> over, equal?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">5</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop, drop2
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   false
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> xxoverx
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, cursor$syntax_rule_set__find, get
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__syntax_rule__unit, subtraction
   <span style="color: #66d9ef; font-weight: bold;">xx</span> syntax_rule__get_predicate
   <span style="color: #66d9ef; font-weight: bold;">xx</span> apply, <span style="color: #f92672; font-weight: bold;">false?branch</span>, (.not_found-$)/cell_size
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop, drop2
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, cursor$syntax_rule_set__find, get
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   V__syntax_rule__unit, subtraction
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   syntax_rule__get_function
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   true
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
<span style="color: #a6e22e;">.not_found</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, cursor$syntax_rule_set__find, get
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__cell_size, subtraction
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__cell_size, subtraction
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, cursor$syntax_rule_set__find, set
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">tail_call</span>, syntax_rule_set__find__loop
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-orgd17150a" class="outline-2">
<h2 id="orgd17150a">jojo-compiler:*syntax-rule-set*</h2>
<div class="outline-text-2" id="text-orgd17150a">
</div><div id="outline-container-orgb22a029" class="outline-3">
<h3 id="orgb22a029"><span class="todo note">note</span> </h3>
<div class="outline-text-3" id="text-orgb22a029">
<ul class="org-ul">
<li><p>a syntax is a function to be called at compile time</p><p>with a string to be compiled as one argument</p><p>and do side-effect to store data into memory</p><p>and return a shorter string</p><p>[this can be viewed as moving a cursor forward]</p></li></ul>
</div>
</div>


<div id="outline-container-orgd892642" class="outline-3">
<h3 id="orgd892642">jojo-compiler-syntax:integer-string</h3>
<div class="outline-text-3" id="text-orgd892642">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"jojo-compiler-syntax:integer-string"</span>, jojo_compiler_syntax__integer_string
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length], word[address, length] --</span>
   <span style="color: #FF8888;">;;    string[address, length] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #f92672; font-weight: bold;">literal</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   jojo_area__stay
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string_to_integer
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   jojo_area__stay
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>


<div id="outline-container-org31f40ce" class="outline-3">
<h3 id="org31f40ce">literal-word:address?</h3>
<div class="outline-text-3" id="text-org31f40ce">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">string$word_is_address?</span>:
   <span style="color: #66d9ef; font-weight: bold;">db</span> <span style="color: #e6db74;">"address"</span>
<span style="color: #a6e22e;">.end</span>:
length$word_is_address? = (.end - string$word_is_address?)

define_function <span style="color: #e6db74;">"literal-word:address?"</span>, word_is_address?
   <span style="color: #FF8888;">;; &lt;&lt; word[address, length] -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, string$word_is_address?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, length$word_is_address?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string_equal?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orgbf4c94c" class="outline-3">
<h3 id="orgbf4c94c">jojo-compiler-syntax:address</h3>
<div class="outline-text-3" id="text-orgbf4c94c">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"jojo-compiler-syntax:address"</span>, jojo_compiler_syntax__address
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length], literal-word:address --</span>
   <span style="color: #FF8888;">;;    string[address, length] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> drop2
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #f92672; font-weight: bold;">address</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   jojo_area__stay
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>


<div id="outline-container-org410343e" class="outline-3">
<h3 id="org410343e">literal-word:jo?</h3>
<div class="outline-text-3" id="text-org410343e">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">string$word_is_jo?</span>:
   <span style="color: #66d9ef; font-weight: bold;">db</span> <span style="color: #e6db74;">"jo"</span>
<span style="color: #a6e22e;">.end</span>:
length$word_is_jo? = (.end - string$word_is_jo?)

define_function <span style="color: #e6db74;">"literal-word:jo?"</span>, word_is_jo?
   <span style="color: #FF8888;">;; &lt;&lt; word[address, length] -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, string$word_is_jo?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, length$word_is_jo?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string_equal?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org6ccc610" class="outline-3">
<h3 id="org6ccc610">jojo-compiler-syntax:jo</h3>
<div class="outline-text-3" id="text-org6ccc610">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"jojo-compiler-syntax:jo"</span>, jojo_compiler_syntax__jo
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length], literal-word:jo --</span>
   <span style="color: #FF8888;">;;    string[address, length] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> drop2
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #f92672; font-weight: bold;">literal</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   jojo_area__stay
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>


<div id="outline-container-org92bb4d1" class="outline-3">
<h3 id="org92bb4d1">literal-word:double-quote?</h3>
<div class="outline-text-3" id="text-org92bb4d1">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">string$word_is_double_quote?</span>:
   <span style="color: #66d9ef; font-weight: bold;">db</span> <span style="color: #e6db74;">'"'</span>
<span style="color: #a6e22e;">.end</span>:
length$word_is_double_quote? = (.end - string$word_is_double_quote?)

define_function <span style="color: #e6db74;">"literal-word:double-quote?"</span>, word_is_double_quote?
   <span style="color: #FF8888;">;; &lt;&lt; word[double-quote, length] -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, string$word_is_double_quote?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, length$word_is_double_quote?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string_equal?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org4c7b403" class="outline-3">
<h3 id="org4c7b403">syntax,double-quote,jojo-compiler</h3>
<div class="outline-text-3" id="text-org4c7b403">
<ul class="org-ul">
<li><p>string-area is used</p><p>to allocate string literal in function body</p></li>
<li><p>in ASCII encode double-quote is 34</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"syntax,double-quote,jojo-compiler"</span>, syntax__double_quote__jojo_compiler
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length], literal-word:double-quote --</span>
   <span style="color: #FF8888;">;;    string[address, length] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> drop2

   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #e6db74;">'"'</span>, string__find_byte
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">false?branch</span>, (.not_found-$)/cell_size
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   xoverxx, subtraction
   <span style="color: #FF8888;">;;   &lt;&lt; string[address, length], new-length &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   xxtuckx
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   xoverxx, swap
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   make_string
   <span style="color: #FF8888;">;;   &lt;&lt; new-length</span>
   <span style="color: #FF8888;">;;      string[address, length]</span>
   <span style="color: #FF8888;">;;      string[address, new-length] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   swap
   <span style="color: #FF8888;">;;   address</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #f92672; font-weight: bold;">literal</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>     jojo_area__stay
   <span style="color: #66d9ef; font-weight: bold;">xx</span>     jojo_area__stay
   <span style="color: #FF8888;">;;   new-length</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #f92672; font-weight: bold;">literal</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>     jojo_area__stay
   <span style="color: #66d9ef; font-weight: bold;">xx</span>     jojo_area__stay
   <span style="color: #FF8888;">;;   &lt;&lt; new-length</span>
   <span style="color: #FF8888;">;;      string[address, length] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   xoverxx, subtraction
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   xxswapx
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   addition
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   swap
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   string__byte_tail <span style="color: #FF8888;">;; over the ending double-quote</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>

   <span style="color: #a6e22e;">.not_found</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> write_not_integer_string_report__for_double_quote
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">10</span>, write_byte
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>


define_function <span style="color: #e6db74;">"write-not-integer-string-report,for-double-quote"</span>, write_not_integer_string_report__for_double_quote
   <span style="color: #FF8888;">;; &lt;&lt; -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, string$not_integer_string_report__for_double_quote
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, length$not_integer_string_report__for_double_quote
   <span style="color: #66d9ef; font-weight: bold;">xx</span> write_string
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>

<span style="color: #a6e22e;">string$not_integer_string_report__for_double_quote</span>:
   <span style="color: #66d9ef; font-weight: bold;">db</span> <span style="color: #e6db74;">"* (syntax,double-quote,jojo-compiler) can not find the ending double-quote"</span>
<span style="color: #a6e22e;">.end</span>:
length$not_integer_string_report__for_double_quote = (.end - string$not_integer_string_report__for_double_quote)
</pre>
</div>
</div>
</div>


<div id="outline-container-orgad1b185" class="outline-3">
<h3 id="orgad1b185"><span class="todo note">note</span> </h3>
<div class="outline-text-3" id="text-orgad1b185">
<ul class="org-ul">
<li><p>comment can not cross ";"</p></li></ul>
</div>
</div>

<div id="outline-container-orgdc6e51e" class="outline-3">
<h3 id="orgdc6e51e">syntax,comment,jojo-compiler</h3>
<div class="outline-text-3" id="text-orgdc6e51e">
<ul class="org-ul">
<li><p>nested &lt;&lt; &gt;&gt; must be handled</p></li>
<li><p>note that</p><p>syntax,comment,jojo-compiler is a syntax</p><p>its interface is special</p><p>thus</p><p>when implement it as one recursive function</p><p>the structure of the function is special</p><p>otherwise</p><p>just implement it by two functions</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"syntax,comment,jojo-compiler"</span>, syntax__comment__jojo_compiler
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length], word --</span>
   <span style="color: #FF8888;">;;    string[address, length] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> drop2
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2, space_string?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">2</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string__word_tail, xxswapxx
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string__word
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2, comment_end_string?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">3</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop2
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2, comment_begin_string?, CICADA__not, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">3</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">tail_call</span>, syntax__comment__jojo_compiler
   <span style="color: #FF8888;">;; nested</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> syntax__comment__jojo_compiler
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2, space_string?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">2</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string__word_tail, xxswapxx
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string__word
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">tail_call</span>, syntax__comment__jojo_compiler
</pre>
</div>
</div>
</div>


<div id="outline-container-orgc37e0a3" class="outline-3">
<h3 id="orgc37e0a3">memory allocation</h3>
<div class="outline-text-3" id="text-orgc37e0a3">
<div class="org-src-container">

<pre class="src src-fasm">size$syntax_rule_set__jojo_compiler = <span style="color: #ae81ff;">1024</span> * cell_size

<span style="color: #a6e22e;">cursor$syntax_rule_set__jojo_compiler</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> address$syntax_rule_set__jojo_compiler
<span style="color: #a6e22e;">address$syntax_rule_set__jojo_compiler</span>:
   <span style="color: #f92672; font-weight: bold;">times</span> size$syntax_rule_set__jojo_compiler <span style="color: #66d9ef; font-weight: bold;">db</span> <span style="color: #ae81ff;">0</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org757600b" class="outline-3">
<h3 id="org757600b">jojo-compiler:*syntax-rule-set*</h3>
<div class="outline-text-3" id="text-org757600b">
<div class="org-src-container">

<pre class="src src-fasm">define_variable <span style="color: #e6db74;">"jojo-compiler:*syntax-rule-set*"</span>, V__syntax_rule_set__jojo_compiler
   <span style="color: #66d9ef; font-weight: bold;">xx</span> address$syntax_rule_set__jojo_compiler
</pre>
</div>
</div>
</div>

<div id="outline-container-org656395c" class="outline-3">
<h3 id="org656395c">init,syntax-rule-set:jojo-compiler</h3>
<div class="outline-text-3" id="text-org656395c">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"init,syntax-rule-set:jojo-compiler"</span>, init__syntax_rule_set__jojo_compiler
   <span style="color: #FF8888;">;; &lt;&lt; -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__syntax_rule_set__jojo_compiler

   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, integer_string?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, jojo_compiler_syntax__integer_string
   <span style="color: #66d9ef; font-weight: bold;">xx</span> syntax_rule__add

   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, word_is_address?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, jojo_compiler_syntax__address
   <span style="color: #66d9ef; font-weight: bold;">xx</span> syntax_rule__add

   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, word_is_jo?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, jojo_compiler_syntax__jo
   <span style="color: #66d9ef; font-weight: bold;">xx</span> syntax_rule__add

   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, word_is_double_quote?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, syntax__double_quote__jojo_compiler
   <span style="color: #66d9ef; font-weight: bold;">xx</span> syntax_rule__add

   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, local_variable_set_word?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, jojo_compiler_syntax__local_variable_set
   <span style="color: #66d9ef; font-weight: bold;">xx</span> syntax_rule__add

   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, local_variable_get_word?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, jojo_compiler_syntax__local_variable_get
   <span style="color: #66d9ef; font-weight: bold;">xx</span> syntax_rule__add

   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, comment_begin_string?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, syntax__comment__jojo_compiler
   <span style="color: #66d9ef; font-weight: bold;">xx</span> syntax_rule__add

   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>
</div>


<div id="outline-container-org5a64627" class="outline-2">
<h2 id="org5a64627">jojo-compiler</h2>
<div class="outline-text-2" id="text-org5a64627">
</div><div id="outline-container-org1fba1e1" class="outline-3">
<h3 id="org1fba1e1"><span class="todo note">note</span> </h3>
<div class="outline-text-3" id="text-org1fba1e1">
<ul class="org-ul">
<li><p>the jojo-compiler is a macro dispatcher</p><p>it can be viewed as make-function-body</p><p>it gets next word and use predicates on word to do dispatch</p></li>
<li><p>note that</p><p>jojo-compiler can be viewed as the "compiler" of the cicada-nymph</p><p>it does NOT (can not) compile file to file</p><p>but creates structured data directly into memory</p></li></ul>
</div>
</div>

<div id="outline-container-org9aff250" class="outline-3">
<h3 id="org9aff250">jojo-compiler,dispatch-word</h3>
<div class="outline-text-3" id="text-org9aff250">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"jojo-compiler,dispatch-word"</span>, jojo_compiler__dispatch_word
   <span style="color: #FF8888;">;; &lt;&lt; jo, string[address, length], word[address, length] --</span>
   <span style="color: #FF8888;">;;    jo, string[address, length] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2
   <span style="color: #66d9ef; font-weight: bold;">xx</span> find_syntax, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">3</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   apply
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__link
   <span style="color: #66d9ef; font-weight: bold;">xx</span> find_link, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">6</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   xxswapx, drop2
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   link_to_jo
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   jojo_area__stay
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> write_undefined_word_report__for_jojo_compiler
   <span style="color: #66d9ef; font-weight: bold;">xx</span> write_string
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">10</span>, write_byte
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>

define_function <span style="color: #e6db74;">"write-undefined-word-report,for-jojo-compiler"</span>, write_undefined_word_report__for_jojo_compiler
   <span style="color: #FF8888;">;; &lt;&lt; -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, string$undefined_word_report__for_jojo_compiler
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, length$undefined_word_report__for_jojo_compiler
   <span style="color: #66d9ef; font-weight: bold;">xx</span> write_string
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>

<span style="color: #a6e22e;">string$undefined_word_report__for_jojo_compiler</span>:
   <span style="color: #66d9ef; font-weight: bold;">db</span> <span style="color: #e6db74;">"* (jojo-compiler) meets undefined word : "</span>
<span style="color: #a6e22e;">.end</span>:
length$undefined_word_report__for_jojo_compiler = (.end - string$undefined_word_report__for_jojo_compiler)
</pre>
</div>
</div>
</div>

<div id="outline-container-org4438378" class="outline-3">
<h3 id="org4438378">jojo-compiler</h3>
<div class="outline-text-3" id="text-org4438378">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"jojo-compiler"</span>, jojo_compiler
   <span style="color: #FF8888;">;; &lt;&lt; jo, string[address, length] -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> local_variable_table__clear
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__syntax_rule_set__jojo_compiler, push_syntax_stack
   <span style="color: #66d9ef; font-weight: bold;">xx</span> jojo_compiler__loop
   <span style="color: #66d9ef; font-weight: bold;">xx</span> drop_syntax_stack
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>

define_function <span style="color: #e6db74;">"jojo-compiler,loop"</span>, jojo_compiler__loop
   <span style="color: #FF8888;">;; &lt;&lt; jo, string[address, length] -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2, space_string?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop2, drop
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string__word_tail
   <span style="color: #66d9ef; font-weight: bold;">xx</span> xxswapxx
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string__word
   <span style="color: #FF8888;">;; &lt;&lt; tail[address, length], head[address, length] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> jojo_compiler__dispatch_word
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">tail_call</span>, jojo_compiler__loop
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-orga1e7859" class="outline-2">
<h2 id="orga1e7859">define-function</h2>
<div class="outline-text-2" id="text-orga1e7859">
</div><div id="outline-container-orgca0225a" class="outline-3">
<h3 id="orgca0225a"><span class="todo note">note</span> </h3>
<div class="outline-text-3" id="text-orgca0225a">
<ul class="org-ul">
<li><p>for the following function</p><p>I add the "CICADA__" as prefix</p><p>to distinguish from their assembly code version</p></li></ul>
</div>
</div>

<div id="outline-container-orgf332061" class="outline-3">
<h3 id="orgf332061">define-function</h3>
<div class="outline-text-3" id="text-orgf332061">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"define-function"</span>, CICADA__define_function
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- &gt;&gt;</span>

   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2, string__word
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length]</span>
   <span style="color: #FF8888;">;;    name-string[address, length] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> make_string
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length]</span>
   <span style="color: #FF8888;">;;    name-string[address, length] &gt;&gt;</span>

   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__link
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">0</span>
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length]</span>
   <span style="color: #FF8888;">;;    name-string[address, length]</span>
   <span style="color: #FF8888;">;;    name-string[address, length], next-link, jo &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> make_link
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length]</span>
   <span style="color: #FF8888;">;;    name-string[address, length]</span>
   <span style="color: #FF8888;">;;    link &gt;&gt;</span>

   <span style="color: #66d9ef; font-weight: bold;">xx</span> xxtuckx
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">address</span>, V__link, set
   <span style="color: #66d9ef; font-weight: bold;">xx</span> drop2
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, explain$function
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">0</span>
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length]</span>
   <span style="color: #FF8888;">;;    link</span>
   <span style="color: #FF8888;">;;    name-string[address, length], explainer, 0 &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> make_jo_head
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length]</span>
   <span style="color: #FF8888;">;;    link</span>
   <span style="color: #FF8888;">;;    jo &gt;&gt;</span>

   <span style="color: #66d9ef; font-weight: bold;">xx</span> tuck
   <span style="color: #66d9ef; font-weight: bold;">xx</span> swap
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length]</span>
   <span style="color: #FF8888;">;;    jo</span>
   <span style="color: #FF8888;">;;    jo</span>
   <span style="color: #FF8888;">;;    link &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> link__set_jo
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length]</span>
   <span style="color: #FF8888;">;;    jo &gt;&gt;</span>

   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> xxswapxx
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string__word_tail
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__jojo_area__current_free_address
   <span style="color: #66d9ef; font-weight: bold;">xx</span> xxxswapx
   <span style="color: #FF8888;">;; &lt;&lt; jo</span>
   <span style="color: #FF8888;">;;    V__jojo_area__current_free_address</span>
   <span style="color: #FF8888;">;;    jo</span>
   <span style="color: #FF8888;">;;    body[address, length] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> jojo_compiler
   <span style="color: #FF8888;">;; &lt;&lt; jo</span>
   <span style="color: #FF8888;">;;    V__jojo_area__current_free_address &gt;&gt;</span>

   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__jojo_area__current_free_address
   <span style="color: #66d9ef; font-weight: bold;">xx</span> swap, subtraction
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__cell_size, division
   <span style="color: #66d9ef; font-weight: bold;">xx</span> swap, jo__set_length

   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org7faa1b7" class="outline-3">
<h3 id="org7faa1b7"><span class="done test">test</span> </h3>
<div class="outline-text-3" id="text-org7faa1b7">
<div class="org-src-container">

<pre class="src src-cicada-nymph"><span style="color: #ffff00; font-weight: bold;">:</span> <span style="color: #ef5939; font-weight: bold;">addadd</span> add add <span style="color: #00ffff; font-weight: bold;">end</span> <span style="color: #ffff00; font-weight: bold;">;</span> <span style="color: #ae81ff; font-weight: bold;">define-function</span>
<span style="color: #fd971f; font-weight: bold;">1</span> <span style="color: #fd971f; font-weight: bold;">2</span> <span style="color: #fd971f; font-weight: bold;">3</span> addadd . <span style="color: #FF8888;">&lt;&lt; 6 &gt;&gt;</span>

<span style="color: #ffff00; font-weight: bold;">:</span> <span style="color: #ef5939; font-weight: bold;">addadd</span> <span style="color: #ffff00; font-weight: bold;">;</span> <span style="color: #ffffff; font-weight: bold;">string:</span>word <span style="color: #fd971f; font-weight: bold;">*link*</span> find-link drop
link<span style="color: #b0b1a3;">-&gt;</span>jo dup jo<span style="color: #b0b1a3;">-&gt;</span>length . <span style="color: #FF8888;">&lt;&lt; 3 &gt;&gt;</span>
<span style="color: #fd971f; font-weight: bold;">1</span> <span style="color: #fd971f; font-weight: bold;">2</span> <span style="color: #fd971f; font-weight: bold;">3</span> x<span style="color: #b0b1a3;">|</span>swap<span style="color: #b0b1a3;">|</span>xxx apply . <span style="color: #FF8888;">&lt;&lt; 6 &gt;&gt;</span>

<span style="color: #ffff00; font-weight: bold;">:</span> <span style="color: #ef5939; font-weight: bold;">add1</span> <span style="color: #fd971f; font-weight: bold;">1</span> add <span style="color: #00ffff; font-weight: bold;">end</span> <span style="color: #ffff00; font-weight: bold;">;</span> <span style="color: #ae81ff; font-weight: bold;">define-function</span>
<span style="color: #fd971f; font-weight: bold;">1</span> add1 . <span style="color: #FF8888;">&lt;&lt; 2 &gt;&gt;</span>

<span style="color: #ffff00; font-weight: bold;">:</span> <span style="color: #ef5939; font-weight: bold;">negate</span> <span style="color: #fd971f; font-weight: bold;">0</span> swap sub <span style="color: #00ffff; font-weight: bold;">end</span> <span style="color: #ffff00; font-weight: bold;">;</span> <span style="color: #ae81ff; font-weight: bold;">define-function</span>
<span style="color: #fd971f; font-weight: bold;">1</span> negate . <span style="color: #FF8888;">&lt;&lt; -1 &gt;&gt;</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org752d8f2" class="outline-3">
<h3 id="org752d8f2"><span class="done test">test</span> double-quote</h3>
<div class="outline-text-3" id="text-org752d8f2">
<div class="org-src-container">

<pre class="src src-cicada-nymph"><span style="color: #ffff00; font-weight: bold;">:</span> <span style="color: #ef5939; font-weight: bold;">test,double-quote</span>
  <span style="color: #FF8888;">&lt;&lt; -- &gt;&gt;</span>
  <span style="color: #e6db74;">"test,double-quote"</span>
  write-string
  <span style="color: #00ffff; font-weight: bold;">end</span>
<span style="color: #ffff00; font-weight: bold;">;</span> <span style="color: #ae81ff; font-weight: bold;">define-function</span>
test,double-quote
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-orgc85753a" class="outline-2">
<h2 id="orgc85753a">define-variable,with-tos</h2>
<div class="outline-text-2" id="text-orgc85753a">
</div><div id="outline-container-org733fbf4" class="outline-3">
<h3 id="org733fbf4">define-variable,with-tos</h3>
<div class="outline-text-3" id="text-org733fbf4">
<ul class="org-ul">
<li><p>not undo is needed for define-variable,with-tos</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"define-variable,with-tos"</span>, CICADA__define_variable__with_tos
   <span style="color: #FF8888;">;; &lt;&lt; value, string[address, length] -- &gt;&gt;</span>

   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2, string__word
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length]</span>
   <span style="color: #FF8888;">;;    name-string[address, length] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> make_string
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length]</span>
   <span style="color: #FF8888;">;;    name-string[address, length] &gt;&gt;</span>

   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__link
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">0</span>
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length]</span>
   <span style="color: #FF8888;">;;    name-string[address, length]</span>
   <span style="color: #FF8888;">;;    name-string[address, length], next-link, jo &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> make_link
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length]</span>
   <span style="color: #FF8888;">;;    name-string[address, length]</span>
   <span style="color: #FF8888;">;;    link &gt;&gt;</span>

   <span style="color: #66d9ef; font-weight: bold;">xx</span> xxtuckx
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">address</span>, V__link, set
   <span style="color: #66d9ef; font-weight: bold;">xx</span> drop2
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, explain$variable
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">0</span>
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length]</span>
   <span style="color: #FF8888;">;;    link</span>
   <span style="color: #FF8888;">;;    name-string[address, length], explainer, 0 &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> make_jo_head
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length]</span>
   <span style="color: #FF8888;">;;    link</span>
   <span style="color: #FF8888;">;;    jo &gt;&gt;</span>

   <span style="color: #66d9ef; font-weight: bold;">xx</span> tuck
   <span style="color: #66d9ef; font-weight: bold;">xx</span> swap
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length]</span>
   <span style="color: #FF8888;">;;    jo</span>
   <span style="color: #FF8888;">;;    jo</span>
   <span style="color: #FF8888;">;;    link &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> link__set_jo
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length]</span>
   <span style="color: #FF8888;">;;    jo &gt;&gt;</span>

   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">1</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> swap
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length]</span>
   <span style="color: #FF8888;">;;    1</span>
   <span style="color: #FF8888;">;;    jo &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> jo__set_length
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] &gt;&gt;</span>

   <span style="color: #66d9ef; font-weight: bold;">xx</span> drop2

   <span style="color: #66d9ef; font-weight: bold;">xx</span> jojo_area__stay

   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org20558be" class="outline-3">
<h3 id="org20558be"><span class="done test">test</span> </h3>
<div class="outline-text-3" id="text-org20558be">
<div class="org-src-container">

<pre class="src src-cicada-nymph"><span style="color: #fd971f; font-weight: bold;">233</span> <span style="color: #ffff00; font-weight: bold;">:</span> <span style="color: #fd971f; font-weight: bold;">*three*</span> <span style="color: #ffff00; font-weight: bold;">;</span> <span style="color: #a1ab3a; font-weight: bold;">define-variable,with-tos</span>
<span style="color: #ffff00; font-weight: bold;">:</span> <span style="color: #ef5939; font-weight: bold;">add-three</span> <span style="color: #fd971f; font-weight: bold;">*three*</span> add <span style="color: #00ffff; font-weight: bold;">end</span> <span style="color: #ffff00; font-weight: bold;">;</span> <span style="color: #ae81ff; font-weight: bold;">define-function</span>
<span style="color: #fd971f; font-weight: bold;">1</span> add-three . <span style="color: #FF8888;">&lt;&lt; 234 &gt;&gt;</span>

<span style="color: #FF8888;">&lt;&lt; you get the address of the variable *three*</span>
<span style="color: #FF8888;">   by add "address" in front of it &gt;&gt;</span>
<span style="color: #ffff00; font-weight: bold;">:</span> <span style="color: #ef5939; font-weight: bold;">fix-*three*</span> <span style="color: #fd971f; font-weight: bold;">3</span> <span style="color: #f92672; font-weight: bold;">address</span> <span style="color: #fd971f; font-weight: bold;">*three*</span> set <span style="color: #00ffff; font-weight: bold;">end</span> <span style="color: #ffff00; font-weight: bold;">;</span> <span style="color: #ae81ff; font-weight: bold;">define-function</span>
fix-<span style="color: #b0b1a3;">*</span>three<span style="color: #b0b1a3;">*</span>
<span style="color: #fd971f; font-weight: bold;">1</span> add-three . <span style="color: #FF8888;">&lt;&lt; 4 &gt;&gt;</span>

<span style="color: #ffff00; font-weight: bold;">:</span> <span style="color: #ef5939; font-weight: bold;">jo-*three*</span> <span style="color: #f92672; font-weight: bold;">jo</span> <span style="color: #fd971f; font-weight: bold;">*three*</span> apply . <span style="color: #00ffff; font-weight: bold;">end</span> <span style="color: #ffff00; font-weight: bold;">;</span> <span style="color: #ae81ff; font-weight: bold;">define-function</span>
jo-<span style="color: #b0b1a3;">*</span>three<span style="color: #b0b1a3;">*</span>
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-orgaa8a50d" class="outline-2">
<h2 id="orgaa8a50d"><b>local-variable</b></h2>
<div class="outline-text-2" id="text-orgaa8a50d">
</div><div id="outline-container-org7bc80d1" class="outline-3">
<h3 id="org7bc80d1"><span class="todo _">記</span> 有名字的局部變量 與 變長的局部數據</h3>
<div class="outline-text-3" id="text-org7bc80d1">
<ul class="org-ul">
<li><p>local-variable</p><p>用來實現 有名字的局部變量</p><p>在編譯時計算 offset</p><p>到這個 local-variable 中的 offset 做爲變量的值</p><p>有 <b>local-variable-table</b> 這個數據結構</p><p>幫助計算 offset</p></li>
<li><p>local-memory</p><p>用來分配 變長的局部數據</p><p>在運行時計算 offset</p></li>
<li><p>兩個機制配合使用</p></li></ul>
</div>
</div>

<div id="outline-container-orgc122860" class="outline-3">
<h3 id="orgc122860"><span class="todo _">記</span> 再增加局部變元支持之後 需要重寫的部分</h3>
<div class="outline-text-3" id="text-orgc122860">
</div><div id="outline-container-org44ecbef" class="outline-4">
<h4 id="org44ecbef">詮釋者 與 收尾詞</h4>
<div class="outline-text-4" id="text-org44ecbef">
<ul class="org-ul">
<li><p>在進行時</p><p>每次進入一個函數體的執行</p><p>即 每次將一串珠珠入棧時</p><p>同時在這串珠子底部加上</p><p>local_variable$current_free_address</p><p>即 在 explain$function 中需要做特殊處理</p></li>
<li><p>這個值在函數退出時</p><p>[即 在 end 這個函數中]</p><p>用以重置 local_variable$current_free_address</p><p>也就是 釋放在這次函數作用過程中所分配的內存</p></li>
<li><p>每次 &gt;:name 的時候</p><p>都更新 local_variable$current_free_address</p><p>以分配內存就行了</p></li>
<li><p>也就是說</p><p>return-stack 中的大多數有效值</p><p>都是以兩個值一對的方式存在的</p></li>
<li><p>兩個結尾詞是 end 和 tail_call</p><p>對於 tail_call</p><p>即 對於明顯的尾遞歸調用</p><p>需要利用棧中的值重置 local_variable$current_free_address</p><p>但是並不入棧新值</p></li></ul>
</div>
</div>

<div id="outline-container-org8fc1e16" class="outline-4">
<h4 id="org8fc1e16">語法擴展方面的支持</h4>
<div class="outline-text-4" id="text-org8fc1e16">
<ul class="org-ul">
<li><p>這裏需要識別 &gt;:name 還有 :name 等等</p><p>並對它們做特殊處理</p><p>這些東西應該藉助設計良好的語法擴展機制來實現</p></li>
<li><p>我將使用一個 語法謂詞 的棧</p><p>可以發現</p><p>這樣的話</p><p>我就能很容易地臨時改變語法了</p></li></ul>
</div>
</div>
</div>

<div id="outline-container-org291d9b4" class="outline-3">
<h3 id="org291d9b4"><span class="todo _">記</span> 總結</h3>
<div class="outline-text-3" id="text-org291d9b4">
</div><div id="outline-container-orga393bd2" class="outline-4">
<h4 id="orga393bd2">interface</h4>
<div class="outline-text-4" id="text-orga393bd2">
<ul class="org-ul">
<li><p>首先要滿足最基本的</p><p>長度爲 <b>cell-size</b> 的倍數的</p><p>局部變量的需求</p><p>其次</p><p>還要能夠在所申請的局部空間裏使用字符串</p><p>這兩種長度的數據結構需要共存</p><p>使用 offset 就行了</p></li>
<li><p>底層</p><p>local-data-allocate,jo</p><p>這個只讓 local_variable$current_free_address 前進</p><p>而不後退</p></li>
<li><p>注意</p><p>最爲重要的特點是</p><p>所有的對 局部數據堆 的使用</p><p>都必須在編譯時期被靜態地算出來</p><p>所以必須設計語法幫助編譯器作計算</p><p>&gt;:name :name 用以 分配 和 使用</p><p><b>cell-size</b> 倍數大小的內存</p></li>
<li><p><p></p><p>語義方面</p><p>&gt;:name 的重複出現有兩種語義</p><p></p></p><p><ol class="org-ol"></p><p><li>更新這個局部變元的值</li></p><p><li>覆蓋上一個局部變元綁定</li></ol></p><p><p></p><p>我選擇第一種</p><p>因爲這樣</p><p>我就不必設計額外的語法來更新局部變元的值了</p><p>比較簡潔</p><p></p></p></li></ul>
</div>
</div>

<div id="outline-container-org2246b7d" class="outline-4">
<h4 id="org2246b7d">語義特點總結</h4>
<div class="outline-text-4" id="text-org2246b7d">
<ul class="org-ul">
<li><p>所有有名局部變元的名字與值的對應</p><p>都由編譯器處理</p></li>
<li><p>每個函數體就是一個非常線性的東西</p><p>函數體中不能嵌套別的函數體</p></li></ul>
</div>
</div>

<div id="outline-container-orgb7e1b4e" class="outline-4">
<h4 id="orgb7e1b4e">語用特點總結</h4>
<div class="outline-text-4" id="text-orgb7e1b4e">
<ul class="org-ul">
<li><p>所有的函數都是全局的</p><p>包括輔助函數</p></li>
<li><p>所以設計輔助函數的時候</p><p>應該格外小心</p><p>儘量使得輔助函數能夠被重用</p></li>
<li><p>改代碼並調整對輔助函數的使用</p><p>就被稱作是 "re-factoring"</p><p>即 函數的因子的重新分解</p></li></ul>
</div>
</div>
</div>

<div id="outline-container-org29d6a3f" class="outline-3">
<h3 id="org29d6a3f"><span class="todo _">記</span> 關於分支結構</h3>
<div class="outline-text-3" id="text-org29d6a3f">
<ul class="org-ul">
<li><p>對 包含 &gt;:name 的函數體的處理是純線性的</p><p>根本沒有考慮到 函數體中 因 if else then 而產生的分支結構</p><p>但是這並不會引起錯誤</p><p>原因如下</p></li>
<li><p>對 &gt;:name 和 :name 的處理是純粹在編譯時期進行的</p></li>
<li><p>所保證的特性是</p><p><ol class="org-ol"></p><p><li>每一個 name 在 一個函數體中的出現</p><p>都是在編譯時期對 local-variable 的 一個 offset 的分配</li></p><p><li>同一個 name 在 一個函數體中的出現</p><p>會得到相同的 offset</li></ol></p></li></ul>
</div>
</div>

<div id="outline-container-org8ea7fa" class="outline-3">
<h3 id="org8ea7fa">memory allocation</h3>
<div class="outline-text-3" id="text-org8ea7fa">
<div class="org-src-container">

<pre class="src src-fasm">size$local_variable = <span style="color: #ae81ff;">1024</span> * <span style="color: #ae81ff;">1024</span> * cell_size

address$local_variable <span style="color: #f92672; font-weight: bold;">labeling</span>
   <span style="color: #66d9ef; font-weight: bold;">preserve</span> size$local_variable

<span style="color: #a6e22e;">local_variable$current_free_address</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> address$local_variable
</pre>
</div>
</div>
</div>

<div id="outline-container-org56b55a2" class="outline-3">
<h3 id="org56b55a2"><span class="todo _">記</span> 注意結尾詞會初始化局部變量指針</h3>
<div class="outline-text-3" id="text-org56b55a2">
<ul class="org-ul">
<li><p>下面的接口函數必須是 primitive-function</p><p>因爲 否則 遇到 end 和 tail_call 的時候</p><p>local_variable$current_free_address 就又被初始化了</p></li></ul>
</div>
</div>

<div id="outline-container-org700f0fc" class="outline-3">
<h3 id="org700f0fc">allocate-local-variable</h3>
<div class="outline-text-3" id="text-org700f0fc">
<div class="org-src-container">

<pre class="src src-fasm">define_primitive_function <span style="color: #e6db74;">"allocate-local-variable"</span>, allocate_local_variable
   <span style="color: #FF8888;">;; &lt;&lt; number -- &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">imul</span> <span style="color: #fd971f;">rax</span>, cell_size
   <span style="color: #a6e22e;">add</span> [local_variable$current_free_address], <span style="color: #fd971f;">rax</span>
   next
</pre>
</div>
</div>
</div>

<div id="outline-container-org75b80aa" class="outline-3">
<h3 id="org75b80aa"><span class="todo note">note</span> many get &amp; set</h3>
<div class="outline-text-3" id="text-org75b80aa">
<ul class="org-ul">
<li><p><p></p><p>in memory</p><p></p></p><p><table border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides"></p><p></p><p></p><p><colgroup></p><p><col  class="org-left" /></p><p></colgroup></p><p><tbody></p><p><tr></p><p><td class="org-left">1 : value-1</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">1 : value-2</td></p><p></tr></p><p></p><p><tr></p><p><td class="org-left">1 : value-3</td></p><p></tr></p><p></tbody></p><p></table></p></li>
<li><p>on stack</p><p>&lt;&lt; value-1, value-2, value-3, &#x2026; &gt;&gt;</p></li></ul>
</div>
</div>

<div id="outline-container-orgb01ebd" class="outline-3">
<h3 id="orgb01ebd">instruction,local-variable,[n-get|n-set]&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span></span></h3>
<div class="outline-text-3" id="text-orgb01ebd">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =64bit, machine {

define_primitive_function <span style="color: #e6db74;">"instruction,local-variable,n-get"</span>, instruction__local_variable__n_get
   <span style="color: #FF8888;">;; &lt;&lt; -- value-1, ..., value-n &gt;&gt;</span>
   pop_return_stack <span style="color: #fd971f;">rbx</span>
     <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rdx</span>, [<span style="color: #fd971f;">rbx</span>]           <span style="color: #FF8888;">;; offset</span>
     <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rcx</span>, [<span style="color: #fd971f;">rbx</span> + cell_size] <span style="color: #FF8888;">;; numebr</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rbx</span>, (cell_size * <span style="color: #ae81ff;">2</span>)
   push_return_stack <span style="color: #fd971f;">rbx</span>

   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [pointer$return_stack - unit__return_point + offset__return_point$local_variable]
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rbx</span>, <span style="color: #fd971f;">rdx</span>
<span style="color: #a6e22e;">.loop</span>:
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rbx</span>]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rbx</span>, cell_size
   <span style="color: #a6e22e;">loop</span> .loop
   next

define_primitive_function <span style="color: #e6db74;">"instruction,local-variable,n-set"</span>, instruction__local_variable__n_set
   <span style="color: #FF8888;">;; &lt;&lt; value-n, ..., value-1 -- &gt;&gt;</span>
   pop_return_stack <span style="color: #fd971f;">rbx</span>
     <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rdx</span>, [<span style="color: #fd971f;">rbx</span>]           <span style="color: #FF8888;">;; offset</span>
     <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rcx</span>, [<span style="color: #fd971f;">rbx</span> + cell_size] <span style="color: #FF8888;">;; numebr</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rbx</span>, (cell_size * <span style="color: #ae81ff;">2</span>)
   push_return_stack <span style="color: #fd971f;">rbx</span>

   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [pointer$return_stack - unit__return_point + offset__return_point$local_variable]
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rbx</span>, <span style="color: #fd971f;">rdx</span>
     <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, cell_size
     <span style="color: #a6e22e;">imul</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">rcx</span>
     <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rbx</span>, <span style="color: #fd971f;">rax</span>
     <span style="color: #FF8888;">;; for address is based on 0</span>
     <span style="color: #FF8888;">;; but n is based on 1</span>
     <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">rbx</span>, cell_size
<span style="color: #a6e22e;">.loop</span>:
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> [<span style="color: #fd971f;">rbx</span>], <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">rbx</span>, cell_size
   <span style="color: #a6e22e;">loop</span> .loop
   next

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org4a121ee" class="outline-3">
<h3 id="org4a121ee">instruction,local-variable,[n-get|n-set]&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span></span></h3>
<div class="outline-text-3" id="text-org4a121ee">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =32bit, machine {

define_primitive_function <span style="color: #e6db74;">"instruction,local-variable,n-get"</span>, instruction__local_variable__n_get
   <span style="color: #FF8888;">;; &lt;&lt; -- value-1, ..., value-n &gt;&gt;</span>
   pop_return_stack <span style="color: #fd971f;">rbx</span>
     <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rdx</span>, [<span style="color: #fd971f;">rbx</span>]           <span style="color: #FF8888;">;; offset</span>
     <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rcx</span>, [<span style="color: #fd971f;">rbx</span> + cell_size] <span style="color: #FF8888;">;; numebr</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rbx</span>, (cell_size * <span style="color: #ae81ff;">2</span>)
   push_return_stack <span style="color: #fd971f;">rbx</span>

   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [pointer$return_stack]
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [<span style="color: #fd971f;">rax</span> - unit__return_point + offset__return_point$local_variable]
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rbx</span>, <span style="color: #fd971f;">rdx</span>
<span style="color: #a6e22e;">.loop</span>:
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [<span style="color: #fd971f;">rbx</span>]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rbx</span>, cell_size
   <span style="color: #a6e22e;">loop</span> .loop
   next

define_primitive_function <span style="color: #e6db74;">"instruction,local-variable,n-set"</span>, instruction__local_variable__n_set
   <span style="color: #FF8888;">;; &lt;&lt; value-n, ..., value-1 -- &gt;&gt;</span>
   pop_return_stack <span style="color: #fd971f;">rbx</span>
     <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rdx</span>, [<span style="color: #fd971f;">rbx</span>]           <span style="color: #FF8888;">;; offset</span>
     <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rcx</span>, [<span style="color: #fd971f;">rbx</span> + cell_size] <span style="color: #FF8888;">;; numebr</span>
   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rbx</span>, (cell_size * <span style="color: #ae81ff;">2</span>)
   push_return_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [pointer$return_stack]
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rbx</span>, [<span style="color: #fd971f;">rax</span> - unit__return_point + offset__return_point$local_variable]

   <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rbx</span>, <span style="color: #fd971f;">rdx</span>
     <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, cell_size
     <span style="color: #a6e22e;">imul</span> <span style="color: #fd971f;">rax</span>, <span style="color: #fd971f;">rcx</span>
     <span style="color: #a6e22e;">add</span> <span style="color: #fd971f;">rbx</span>, <span style="color: #fd971f;">rax</span>
     <span style="color: #FF8888;">;; for address is based on 0</span>
     <span style="color: #FF8888;">;; but n is based on 1</span>
     <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">rbx</span>, cell_size
<span style="color: #a6e22e;">.loop</span>:
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">mov</span> [<span style="color: #fd971f;">rbx</span>], <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">rbx</span>, cell_size
   <span style="color: #a6e22e;">loop</span> .loop
   next

}
</pre>
</div>
</div>
</div>

<div id="outline-container-orgb567284" class="outline-3">
<h3 id="orgb567284"><span class="todo note">note</span> example result</h3>
<div class="outline-text-3" id="text-orgb567284">
<ul class="org-ul">
<li><p><p></p><p>example</p><p></p></p><p><div class="org-src-container"></p><p></p><p><pre class="src src-cicada-nymph"><span style="color: #ffff00; font-weight: bold;">:</span> <span style="color: #ef5939; font-weight: bold;">example</span></p><p>  <span style="color: #FF8888;">&lt;&lt; number1, number2, number3, number4</span></p><p><span style="color: #FF8888;">     -- number1, number2 &gt;&gt;</span></p><p>  <span style="color: #dc322f; font-weight: bold;">&gt;::var2</span></p><p>  <span style="color: #dc322f; font-weight: bold;">&gt;::var2</span></p><p>  <span style="color: #5CDD5C; font-weight: bold;">::var2</span></p><p>  <span style="color: #00ffff; font-weight: bold;">end</span></p><p><span style="color: #ffff00; font-weight: bold;">;</span> <span style="color: #ae81ff; font-weight: bold;">define-function</span></p><p></pre></p><p></div></p></li>
<li><p><p></p><p>result</p><p></p></p><p><div class="org-src-container"></p><p></p><p><pre class="src src-fasm">define_function <span style="color: #e6db74;">"example"</span>, example</p><p></p><p>   <span style="color: #FF8888;">;; &gt;::var2</span></p><p>   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">2</span>, allocate_local_variable</p><p>   <span style="color: #66d9ef; font-weight: bold;">xx</span> instruction__local_variable__n_set, <span style="color: #ae81ff;">0</span>, <span style="color: #ae81ff;">2</span></p><p></p><p>   <span style="color: #FF8888;">;; &gt;::var2</span></p><p>   <span style="color: #66d9ef; font-weight: bold;">xx</span> instruction__local_variable__n_set, <span style="color: #ae81ff;">0</span>, <span style="color: #ae81ff;">2</span></p><p></p><p>   <span style="color: #FF8888;">;; ::var2</span></p><p>   <span style="color: #66d9ef; font-weight: bold;">xx</span> instruction__local_variable__n_get, <span style="color: #ae81ff;">0</span>, <span style="color: #ae81ff;">2</span></p><p></p><p>   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span></p><p></pre></p><p></div></p></li></ul>
</div>
</div>

<div id="outline-container-orgbbd6bfe" class="outline-3">
<h3 id="orgbbd6bfe"><span class="done test">test</span> </h3>
<div class="outline-text-3" id="text-orgbbd6bfe">
<div class="org-src-container">

<pre class="src src-cicada-nymph"><span style="color: #ffff00; font-weight: bold;">:</span> <span style="color: #ef5939; font-weight: bold;">local-variable,test</span>
  <span style="color: #FF4C4C; font-weight: bold;">&gt;:var1</span>
  <span style="color: #83EA83; font-weight: bold;">:var1</span>
  <span style="color: #00ffff; font-weight: bold;">end</span>
<span style="color: #ffff00; font-weight: bold;">;</span> <span style="color: #ae81ff; font-weight: bold;">define-function</span>
<span style="color: #fd971f; font-weight: bold;">1</span> local-variable,test .
<span style="color: #FF8888;">&lt;&lt; 1 &gt;&gt;</span>

<span style="color: #ffff00; font-weight: bold;">:</span> <span style="color: #ef5939; font-weight: bold;">local-variable,test</span>
  <span style="color: #FF4C4C; font-weight: bold;">&gt;:var1</span>
  <span style="color: #FF4C4C; font-weight: bold;">&gt;:var2</span>
  <span style="color: #FF4C4C; font-weight: bold;">&gt;:var3</span>
  <span style="color: #FF4C4C; font-weight: bold;">&gt;:var4</span>
  <span style="color: #83EA83; font-weight: bold;">:var4</span>
  <span style="color: #83EA83; font-weight: bold;">:var3</span>
  <span style="color: #83EA83; font-weight: bold;">:var2</span>
  <span style="color: #83EA83; font-weight: bold;">:var1</span>
  <span style="color: #00ffff; font-weight: bold;">end</span>
<span style="color: #ffff00; font-weight: bold;">;</span> <span style="color: #ae81ff; font-weight: bold;">define-function</span>
<span style="color: #fd971f; font-weight: bold;">1</span> <span style="color: #fd971f; font-weight: bold;">2</span> <span style="color: #fd971f; font-weight: bold;">3</span> <span style="color: #fd971f; font-weight: bold;">4</span> local-variable,test . . . .
<span style="color: #FF8888;">&lt;&lt; 4 3 2 1 &gt;&gt;</span>

<span style="color: #ffff00; font-weight: bold;">:</span> <span style="color: #ef5939; font-weight: bold;">local-variable,test</span>
  <span style="color: #FF4C4C; font-weight: bold;">&gt;:var2</span>
  <span style="color: #FF4C4C; font-weight: bold;">&gt;:var2</span>
  <span style="color: #FF4C4C; font-weight: bold;">&gt;:var1</span>
  <span style="color: #83EA83; font-weight: bold;">:var1</span>
  <span style="color: #83EA83; font-weight: bold;">:var2</span>
  add
  <span style="color: #00ffff; font-weight: bold;">end</span>
<span style="color: #ffff00; font-weight: bold;">;</span> <span style="color: #ae81ff; font-weight: bold;">define-function</span>
<span style="color: #fd971f; font-weight: bold;">1</span> <span style="color: #fd971f; font-weight: bold;">2</span> <span style="color: #fd971f; font-weight: bold;">4</span> local-variable,test .
<span style="color: #FF8888;">&lt;&lt; 3 &gt;&gt;</span>

<span style="color: #ffff00; font-weight: bold;">:</span> <span style="color: #ef5939; font-weight: bold;">local-variable,test,2</span>
  <span style="color: #FF8888;">&lt;&lt; number1, number2 -- number2 + number3 &gt;&gt;</span>
  <span style="color: #dc322f; font-weight: bold;">&gt;::var2</span>
  <span style="color: #5CDD5C; font-weight: bold;">::var2</span>
  <span style="color: #00ffff; font-weight: bold;">end</span>
<span style="color: #ffff00; font-weight: bold;">;</span> <span style="color: #ae81ff; font-weight: bold;">define-function</span>
<span style="color: #fd971f; font-weight: bold;">1</span> <span style="color: #fd971f; font-weight: bold;">2</span> local-variable,test,2 . .
<span style="color: #FF8888;">&lt;&lt; 1 2 &gt;&gt;</span>

<span style="color: #ffff00; font-weight: bold;">:</span> <span style="color: #ef5939; font-weight: bold;">local-variable,test,3</span>
  <span style="color: #FF8888;">&lt;&lt; number1, number2, number3 -- number2 + number3 &gt;&gt;</span>
  <span style="color: #dc322f; font-weight: bold;">&gt;::var2</span>
  <span style="color: #FF4C4C; font-weight: bold;">&gt;:var1</span>
  <span style="color: #5CDD5C; font-weight: bold;">::var2</span>
  add
  <span style="color: #00ffff; font-weight: bold;">end</span>
<span style="color: #ffff00; font-weight: bold;">;</span> <span style="color: #ae81ff; font-weight: bold;">define-function</span>
<span style="color: #fd971f; font-weight: bold;">1</span> <span style="color: #fd971f; font-weight: bold;">2</span> <span style="color: #fd971f; font-weight: bold;">4</span> local-variable,test,3 .
<span style="color: #FF8888;">&lt;&lt; 6 &gt;&gt;</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org8b46ad8" class="outline-3">
<h3 id="org8b46ad8"><span class="done test">test</span> nested call</h3>
<div class="outline-text-3" id="text-org8b46ad8">
<div class="org-src-container">

<pre class="src src-cicada-nymph"><span style="color: #ffff00; font-weight: bold;">:</span> <span style="color: #ef5939; font-weight: bold;">k1</span>
  <span style="color: #fd971f; font-weight: bold;">9</span> <span style="color: #FF4C4C; font-weight: bold;">&gt;:k</span>
  <span style="color: #83EA83; font-weight: bold;">:k</span> .
  <span style="color: #00ffff; font-weight: bold;">end</span>
<span style="color: #ffff00; font-weight: bold;">;</span> <span style="color: #ae81ff; font-weight: bold;">define-function</span>
k1 <span style="color: #FF8888;">&lt;&lt; 9 &gt;&gt;</span>

<span style="color: #ffff00; font-weight: bold;">:</span> <span style="color: #ef5939; font-weight: bold;">k2</span>
  <span style="color: #fd971f; font-weight: bold;">10</span> <span style="color: #FF4C4C; font-weight: bold;">&gt;:k</span>
  k1
  <span style="color: #83EA83; font-weight: bold;">:k</span> .
  <span style="color: #00ffff; font-weight: bold;">end</span>
<span style="color: #ffff00; font-weight: bold;">;</span> <span style="color: #ae81ff; font-weight: bold;">define-function</span>
k2 <span style="color: #FF8888;">&lt;&lt; 9 10 &gt;&gt;</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orgb1f9bd9" class="outline-3">
<h3 id="orgb1f9bd9"><span class="todo _">記</span> 問題</h3>
<div class="outline-text-3" id="text-orgb1f9bd9">
</div><div id="outline-container-org243fff0" class="outline-4">
<h4 id="org243fff0">nested block</h4>
<div class="outline-text-4" id="text-org243fff0">
<ul class="org-ul">
<li><p>因爲使用全局的 local-variable-table</p><p>所以沒法在 nested block 中使用 local-variable</p></li></ul>
</div>
</div>

<div id="outline-container-org7a406c5" class="outline-4">
<h4 id="org7a406c5">branch</h4>
<div class="outline-text-4" id="text-org7a406c5">
<ul class="org-ul">
<li><p><p></p><p>example</p><p></p></p><p><div class="org-src-container"></p><p></p><p><pre class="src src-cicada-nymph"><span style="color: #ffff00; font-weight: bold;">:</span> <span style="color: #ef5939; font-weight: bold;">example</span></p><p>  <span style="color: #FF8888;">&lt;&lt; number1, number2, number3, number4</span></p><p><span style="color: #FF8888;">     -- number1, number2 &gt;&gt;</span></p><p>  <span style="color: #dc322f; font-weight: bold;">&gt;::var2</span></p><p>  <span style="color: #dc322f; font-weight: bold;">&gt;::var2</span></p><p>  <span style="color: #5CDD5C; font-weight: bold;">::var2</span></p><p>  <span style="color: #00ffff; font-weight: bold;">end</span></p><p><span style="color: #ffff00; font-weight: bold;">;</span> <span style="color: #ae81ff; font-weight: bold;">define-function</span></p><p></pre></p><p></div></p></li>
<li><p><p></p><p>result</p><p></p></p><p><div class="org-src-container"></p><p></p><p><pre class="src src-fasm">define_function <span style="color: #e6db74;">"example"</span>, example</p><p></p><p>   <span style="color: #FF8888;">;; &gt;::var2</span></p><p>   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">2</span>, allocate_local_variable</p><p>   <span style="color: #66d9ef; font-weight: bold;">xx</span> instruction__local_variable__n_set, <span style="color: #ae81ff;">0</span>, <span style="color: #ae81ff;">2</span></p><p></p><p>   <span style="color: #FF8888;">;; &gt;::var2</span></p><p>   <span style="color: #66d9ef; font-weight: bold;">xx</span> instruction__local_variable__n_set, <span style="color: #ae81ff;">0</span>, <span style="color: #ae81ff;">2</span></p><p></p><p>   <span style="color: #FF8888;">;; ::var2</span></p><p>   <span style="color: #66d9ef; font-weight: bold;">xx</span> instruction__local_variable__n_get, <span style="color: #ae81ff;">0</span>, <span style="color: #ae81ff;">2</span></p><p></p><p>   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span></p><p></pre></p><p></div></p></li>
<li><p><p></p><p>看上面的例子</p><p>可以發現</p><p></p></p><p><div class="org-src-container"></p><p></p><p><pre class="src src-cicada-nymph"><span style="color: #ffff00; font-weight: bold;">:</span> <span style="color: #ef5939; font-weight: bold;">example</span></p><p>  <span style="color: #f92672; font-weight: bold;">if</span></p><p>    <span style="color: #dc322f; font-weight: bold;">&gt;::var2</span></p><p>  <span style="color: #f92672; font-weight: bold;">else</span></p><p>    <span style="color: #dc322f; font-weight: bold;">&gt;::var2</span></p><p>  <span style="color: #f92672; font-weight: bold;">then</span></p><p>  <span style="color: #5CDD5C; font-weight: bold;">::var2</span></p><p>  <span style="color: #00ffff; font-weight: bold;">end</span></p><p><span style="color: #ffff00; font-weight: bold;">;</span> <span style="color: #ae81ff; font-weight: bold;">define-function</span></p><p></pre></p><p></div></p><p><p></p><p>不同分支下</p><p>局部變元的編譯效果不等同了</p><p></p></p></li></ul>
</div>
</div>
</div>

<div id="outline-container-orgf0091a0" class="outline-3">
<h3 id="orgf0091a0">local-variable-table</h3>
<div class="outline-text-3" id="text-orgf0091a0">
</div><div id="outline-container-org990a0bc" class="outline-4">
<h4 id="org990a0bc"><span class="todo _">記</span> </h4>
<div class="outline-text-4" id="text-org990a0bc">
<ul class="org-ul">
<li><p>只有一個 local-variable-table</p><p>用以在編譯時期解決局部變元的名與值的對應</p><p>這個數據結構被 jojo_compiler_syntax__local_variable_set</p><p>和 jojo_compiler_syntax__local_variable_get 所使用</p></li>
<li><p>其中保存</p><p><ul class="org-ul"></p><p><li><p>offset-in-local-variable</p></li></p><p><li><p>length-of-string</p></li></p><p><li><p>address-of-string</p></li></ul></p></li>
<li><p>並且每次在定義一個新的函數體的時候</p><p>這個 local-variable-table 會被初始化</p></li></ul>
</div>
</div>

<div id="outline-container-org4ceb115" class="outline-4">
<h4 id="org4ceb115"><span class="todo _">記</span> 接口</h4>
<div class="outline-text-4" id="text-org4ceb115">
<ul class="org-ul">
<li><p>(clear)</p><p>清空 offset 和 border</p></li>
<li><p>(insert)</p><p>插入字符串 和 offset-in-local-variable</p></li>
<li><p>(find)</p><p>通過字符串尋找 offset-in-local-variable</p></li>
<li><p>有兩個全局變量幫助實現這些接口</p><p><ul class="org-ul"></p><p><li><p>(cursor)</p><p>每次 find 的時候使用一個新的 cursor 來做循環</p></li></p><p><li><p>(border)</p><p>insert 會擴大 border</p><p>find 以 border 爲邊界</p></li></ul></p></li>
<li><p>另外 還有一個全局變量</p><p><ul class="org-ul"></p><p><li><p>(offset)</p><p>用以計算 offset-in-local-variable</p></li></ul></p></li></ul>
</div>
</div>

<div id="outline-container-orgb56c063" class="outline-4">
<h4 id="orgb56c063">memory allocation</h4>
<div class="outline-text-4" id="text-orgb56c063">
<div class="org-src-container">

<pre class="src src-fasm">size$local_variable_table = <span style="color: #ae81ff;">100</span> * <span style="color: #ae81ff;">1024</span>

address$local_variable_table <span style="color: #f92672; font-weight: bold;">labeling</span>
   <span style="color: #66d9ef; font-weight: bold;">preserve</span> size$local_variable_table
</pre>
</div>
</div>
</div>

<div id="outline-container-orgf8211ec" class="outline-4">
<h4 id="orgf8211ec">local-variable-table,clear</h4>
<div class="outline-text-4" id="text-orgf8211ec">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">border$local_variable_table</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> address$local_variable_table

<span style="color: #a6e22e;">offset$local_variable_table</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #ae81ff;">0</span>

define_function <span style="color: #e6db74;">"local-variable-table,clear"</span>, local_variable_table__clear
   <span style="color: #FF8888;">;; &lt;&lt; -- &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, address$local_variable_table
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, border$local_variable_table, set
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">0</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, offset$local_variable_table, set
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orga312bad" class="outline-4">
<h4 id="orga312bad">local-variable-table,insert</h4>
<div class="outline-text-4" id="text-orga312bad">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"local-variable-table,insert"</span>, local_variable_table__insert
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- offset &gt;&gt;</span>

   <span style="color: #FF8888;">;; leave offset</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, offset$local_variable_table, get
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   xxtuckx <span style="color: #FF8888;">;; return value</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, border$local_variable_table, get, set
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__cell_size
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, border$local_variable_table, add_set

   <span style="color: #FF8888;">;; update offset$local_variable_table</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   count_front_colon
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   V__cell_size, multiple
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, offset$local_variable_table, add_set

   <span style="color: #FF8888;">;; leave length</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, border$local_variable_table, get, set
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__cell_size
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, border$local_variable_table, add_set

   <span style="color: #66d9ef; font-weight: bold;">xx</span> tuck <span style="color: #FF8888;">;; for to update border$local_variable_table</span>

   <span style="color: #FF8888;">;; leave string</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, border$local_variable_table, get
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string_to_buffer!

   <span style="color: #FF8888;">;; update border$local_variable_table</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, border$local_variable_table, add_set

   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orgd07431d" class="outline-4">
<h4 id="orgd07431d">local-variable-table,find</h4>
<div class="outline-text-4" id="text-orgd07431d">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">cursor$local_variable_table</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> address$local_variable_table

define_function <span style="color: #e6db74;">"local-variable-table,find"</span>, local_variable_table__find
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length]</span>
   <span style="color: #FF8888;">;;    -- offset, true</span>
   <span style="color: #FF8888;">;;    -- false &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, address$local_variable_table
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, cursor$local_variable_table, set
   <span style="color: #66d9ef; font-weight: bold;">xx</span> local_variable_table__find__loop
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>

define_function <span style="color: #e6db74;">"local-variable-table,find,loop"</span>, local_variable_table__find__loop
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length]</span>
   <span style="color: #FF8888;">;;    -- offset, true</span>
   <span style="color: #FF8888;">;;    -- false &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, cursor$local_variable_table, get
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, border$local_variable_table, get
   <span style="color: #66d9ef; font-weight: bold;">xx</span> greater_or_equal?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop2
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   false
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, cursor$local_variable_table, get
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   V__cell_size, addition
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   V__cell_size, addition <span style="color: #FF8888;">;; address of string</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, cursor$local_variable_table, get
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   V__cell_size, addition
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   get <span style="color: #FF8888;">;; length of string</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string_equal?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">8</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop2
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, cursor$local_variable_table, get
   <span style="color: #66d9ef; font-weight: bold;">xx</span>     get <span style="color: #FF8888;">;; offset</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   true
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, cursor$local_variable_table, get
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   V__cell_size, addition
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   get <span style="color: #FF8888;">;; length of string</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__cell_size, addition
   <span style="color: #66d9ef; font-weight: bold;">xx</span> V__cell_size, addition
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, cursor$local_variable_table, add_set
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">tail_call</span>, local_variable_table__find__loop
</pre>
</div>
</div>
</div>

<div id="outline-container-org47a30d8" class="outline-4">
<h4 id="org47a30d8">count-front-colon</h4>
<div class="outline-text-4" id="text-org47a30d8">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"count-front-colon"</span>, count_front_colon
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- number &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">0</span> <span style="color: #FF8888;">;; counter</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> count_front_colon__loop
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>

define_function <span style="color: #e6db74;">"count-front-colon,loop"</span>, count_front_colon__loop
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length], counter -- number &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> over, zero?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   xxswapx, drop2
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> xxoverx, string__byte
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #e6db74;">':'</span>, equal?, false?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   xxswapx, drop2
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> add1, xxswapx
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string__byte_tail, xswapxx
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">tail_call</span>, count_front_colon__loop
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-orga240090" class="outline-3">
<h3 id="orga240090">two syntaxes</h3>
<div class="outline-text-3" id="text-orga240090">
</div><div id="outline-container-org9751635" class="outline-4">
<h4 id="org9751635">local-variable-get-word?</h4>
<div class="outline-text-4" id="text-org9751635">
<ul class="org-ul">
<li><p>:name</p><p>::name</p></li>
<li><p>but not</p><p>:name:</p><p>::name:</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"local-variable-get-word?"</span>, local_variable_get_word?
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>, zero?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop2, false
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2, addition, sub1
   <span style="color: #66d9ef; font-weight: bold;">xx</span> get_byte, <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #e6db74;">':'</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> equal?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop2, false
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2, count_front_colon
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>, <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">0</span>, greater_than?, false?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">5</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop, drop2, false
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> subtraction
   <span style="color: #66d9ef; font-weight: bold;">xx</span> swap, drop
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">0</span>, greater_than?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org93f4856" class="outline-4">
<h4 id="org93f4856">jojo-compiler-syntax:local-variable-get</h4>
<div class="outline-text-4" id="text-org93f4856">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"jojo-compiler-syntax:local-variable-get"</span>, jojo_compiler_syntax__local_variable_get
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length], word[address, length] --</span>
   <span style="color: #FF8888;">;;    string[address, length] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2
   <span style="color: #66d9ef; font-weight: bold;">xx</span> local_variable_table__find, <span style="color: #f92672; font-weight: bold;">false?branch</span>, (.not_found-$)/cell_size
   <span style="color: #FF8888;">;;   instruction__local_variable__n_get, &lt;offese&gt;, n</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>     <span style="color: #f92672; font-weight: bold;">literal</span>, instruction__local_variable__n_get
   <span style="color: #66d9ef; font-weight: bold;">xx</span>       jojo_area__stay
   <span style="color: #FF8888;">;;     offset</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>       jojo_area__stay
   <span style="color: #FF8888;">;;     n</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>     count_front_colon
   <span style="color: #66d9ef; font-weight: bold;">xx</span>       jojo_area__stay
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
<span style="color: #a6e22e;">.not_found</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> write_local_variable_not_bound_report
   <span style="color: #66d9ef; font-weight: bold;">xx</span> write_string
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">10</span>, write_byte
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>

define_function <span style="color: #e6db74;">"write-local-variable-not-bound-report"</span>, write_local_variable_not_bound_report
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, string$local_variable_not_bound_report
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, length$local_variable_not_bound_report
   <span style="color: #66d9ef; font-weight: bold;">xx</span> write_string
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>

<span style="color: #a6e22e;">string$local_variable_not_bound_report</span>:
   <span style="color: #66d9ef; font-weight: bold;">db</span> <span style="color: #e6db74;">"* local-variable not bound : "</span>
<span style="color: #a6e22e;">.end</span>:
length$local_variable_not_bound_report = (.end - string$local_variable_not_bound_report)
</pre>
</div>
</div>
</div>


<div id="outline-container-org27232be" class="outline-4">
<h4 id="org27232be">local-variable-set-word?</h4>
<div class="outline-text-4" id="text-org27232be">
<ul class="org-ul">
<li><p>&gt;:name</p><p>&gt;::name</p></li>
<li><p>but not</p><p>&gt;:name:</p><p>&gt;::name:</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"local-variable-set-word?"</span>, local_variable_set_word?
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- bool &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>, zero?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop2, false
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2, addition, sub1
   <span style="color: #66d9ef; font-weight: bold;">xx</span> get_byte, <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #e6db74;">':'</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> equal?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop2, false
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2, string__byte
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #e6db74;">'&gt;'</span>, equal?, false?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop2, false
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string__byte_tail
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2, count_front_colon
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>, <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">0</span>, greater_than?, false?, <span style="color: #f92672; font-weight: bold;">false?branch</span>, <span style="color: #ae81ff;">5</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   drop, drop2, false
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> subtraction
   <span style="color: #66d9ef; font-weight: bold;">xx</span> swap, drop
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">0</span>, greater_than?
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-orge896885" class="outline-4">
<h4 id="orge896885">jojo-compiler-syntax:local-variable-set</h4>
<div class="outline-text-4" id="text-orge896885">
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"jojo-compiler-syntax:local-variable-set"</span>, jojo_compiler_syntax__local_variable_set
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length], word[address, length] --</span>
   <span style="color: #FF8888;">;;    string[address, length] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string__byte_tail
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2
   <span style="color: #66d9ef; font-weight: bold;">xx</span> local_variable_table__find, <span style="color: #f92672; font-weight: bold;">false?branch</span>, (.not_found-$)/cell_size
   <span style="color: #FF8888;">;;   instruction__local_variable__n_set, &lt;offese&gt;, n</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>     <span style="color: #f92672; font-weight: bold;">literal</span>, instruction__local_variable__n_set
   <span style="color: #66d9ef; font-weight: bold;">xx</span>       jojo_area__stay
   <span style="color: #FF8888;">;;     offset</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>       jojo_area__stay
   <span style="color: #FF8888;">;;     n</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>     count_front_colon
   <span style="color: #66d9ef; font-weight: bold;">xx</span>       jojo_area__stay
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">end</span>
<span style="color: #a6e22e;">.not_found</span>:
   <span style="color: #66d9ef; font-weight: bold;">xx</span> dup2
   <span style="color: #66d9ef; font-weight: bold;">xx</span> local_variable_table__insert
   <span style="color: #66d9ef; font-weight: bold;">xx</span> xxswapx
   <span style="color: #66d9ef; font-weight: bold;">xx</span> count_front_colon
   <span style="color: #FF8888;">;; literal, &lt;number&gt;, allocate_local_variable</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #f92672; font-weight: bold;">literal</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>     jojo_area__stay
   <span style="color: #FF8888;">;;   number of jo</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>     <span style="color: #f92672; font-weight: bold;">dup</span>, jojo_area__stay
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, allocate_local_variable
   <span style="color: #66d9ef; font-weight: bold;">xx</span>     jojo_area__stay
   <span style="color: #FF8888;">;; instruction__local_variable__n_set, &lt;offese&gt;, n</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, instruction__local_variable__n_set
   <span style="color: #66d9ef; font-weight: bold;">xx</span>     jojo_area__stay
   <span style="color: #FF8888;">;;   offset</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   swap
   <span style="color: #66d9ef; font-weight: bold;">xx</span>     jojo_area__stay
   <span style="color: #FF8888;">;;   n</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>     jojo_area__stay
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>
</div>
</div>


<div id="outline-container-orgf9d9978" class="outline-2">
<h2 id="orgf9d9978"><b>local-memory</b></h2>
<div class="outline-text-2" id="text-orgf9d9978">
</div><div id="outline-container-org3020c92" class="outline-3">
<h3 id="org3020c92"><span class="todo _">記</span> </h3>
<div class="outline-text-3" id="text-org3020c92">
<ul class="org-ul">
<li><p>並不需要給這裏的接口設計特殊的語法擴展</p><p>直接使用函數就可以了</p></li>
<li><p>但是接口必須是 primitive-function</p><p>因爲 否則 遇到 end 和 tail_call 的時候</p><p>local_memory 就又被初始化了</p></li></ul>
</div>
</div>

<div id="outline-container-orgb0073e5" class="outline-3">
<h3 id="orgb0073e5"><span class="todo _">記</span> 使用</h3>
<div class="outline-text-3" id="text-orgb0073e5">
<ul class="org-ul">
<li><p>在一個函數內</p><p>用 allocate-local-memory 所申請的局部數據空間</p><p>是可以被這個函數內所調用的函數所使用的</p><p>但是當函數退出的時候</p><p>其所申請的空間就被結尾珠 (end) 收回了</p><p>而沒法重用了</p><p>而用 (tail-call) 來實現循環的時候</p><p>下一次函數的執行過程中</p><p>所申請的 allocate-local-memory</p><p>和上一次函數執行過程中</p><p>所申請的 allocate-local-memory 是相同的</p></li></ul>
</div>
</div>

<div id="outline-container-org569a159" class="outline-3">
<h3 id="org569a159"><b>local-memory-even</b></h3>
<div class="outline-text-3" id="text-org569a159">
<div class="org-src-container">

<pre class="src src-fasm">size$local_memory_even = <span style="color: #ae81ff;">1024</span> * <span style="color: #ae81ff;">1024</span> * <span style="color: #ae81ff;">6</span>

address$local_memory_even <span style="color: #f92672; font-weight: bold;">labeling</span>
   <span style="color: #66d9ef; font-weight: bold;">preserve</span> size$local_memory_even

define_variable <span style="color: #e6db74;">"*local-memory-even,current-free-address*"</span>, V__local_memory_even__current_free_address
   <span style="color: #66d9ef; font-weight: bold;">xx</span> address$local_memory_even
</pre>
</div>
</div>
</div>

<div id="outline-container-orgcac0793" class="outline-3">
<h3 id="orgcac0793"><b>local-memory-odd</b></h3>
<div class="outline-text-3" id="text-orgcac0793">
<div class="org-src-container">

<pre class="src src-fasm">size$local_memory_odd = <span style="color: #ae81ff;">1024</span> * <span style="color: #ae81ff;">1024</span> * <span style="color: #ae81ff;">6</span>

address$local_memory_odd <span style="color: #f92672; font-weight: bold;">labeling</span>
   <span style="color: #66d9ef; font-weight: bold;">preserve</span> size$local_memory_odd

define_variable <span style="color: #e6db74;">"*local-memory-odd,current-free-address*"</span>, V__local_memory_odd__current_free_address
   <span style="color: #66d9ef; font-weight: bold;">xx</span> address$local_memory_odd
</pre>
</div>
</div>
</div>

<div id="outline-container-org20074ce" class="outline-3">
<h3 id="org20074ce"><span class="todo _">記</span> 奇偶性</h3>
<div class="outline-text-3" id="text-org20074ce">
<ul class="org-ul">
<li><p>用 返回棧指針 來判斷 奇偶性</p><p>對 explain$function 來說</p><p>當前的 return-point 就是 返回棧指針</p><p>對 結尾珠 還有 下面的兩個函數來說</p><p>當前的 return-point 就是 返回棧指針 之前的 一個單位</p></li>
<li><p>在偶的 return-point</p><p>其中 local-memory 域 是 local-memory-even</p><p>其中 conjugate-local-memory 域 是 local-memory-odd</p><p>在奇的 return-point 則相反</p></li>
<li><p>函數退出時只重置 local-memory 而不重置 conjugate-local-memory</p></li></ul>
</div>
</div>

<div id="outline-container-org8c29d59" class="outline-3">
<h3 id="org8c29d59">allocate-local-memory</h3>
<div class="outline-text-3" id="text-org8c29d59">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =64bit, machine {

define_primitive_function <span style="color: #e6db74;">"allocate-local-memory"</span>, allocate_local_memory
   <span style="color: #FF8888;">;; &lt;&lt; size -- address &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, pointer$return_stack
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">rax</span>, address$return_stack
   <span style="color: #a6e22e;">test</span> <span style="color: #fd971f;">rax</span>, unit__return_point
   <span style="color: #a6e22e;">jnz</span> .return_stack_even

   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [V__local_memory_odd__current_free_address + cell_size]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">add</span> [V__local_memory_odd__current_free_address + cell_size], <span style="color: #fd971f;">rbx</span>
   next

<span style="color: #a6e22e;">.return_stack_even</span>:
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [V__local_memory_even__current_free_address + cell_size]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">add</span> [V__local_memory_even__current_free_address + cell_size], <span style="color: #fd971f;">rbx</span>
   next

}

<span style="color: #a6e22e;">match</span> =32bit, machine {

define_primitive_function <span style="color: #e6db74;">"allocate-local-memory"</span>, allocate_local_memory
   <span style="color: #FF8888;">;; &lt;&lt; size -- address &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [pointer$return_stack]
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">rax</span>, address$return_stack
   <span style="color: #a6e22e;">test</span> <span style="color: #fd971f;">rax</span>, unit__return_point
   <span style="color: #a6e22e;">jnz</span> .return_stack_even

   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [V__local_memory_odd__current_free_address + cell_size]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">add</span> [V__local_memory_odd__current_free_address + cell_size], <span style="color: #fd971f;">rbx</span>
   next

<span style="color: #a6e22e;">.return_stack_even</span>:
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [V__local_memory_even__current_free_address + cell_size]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">add</span> [V__local_memory_even__current_free_address + cell_size], <span style="color: #fd971f;">rbx</span>
   next

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org7bf71e9" class="outline-3">
<h3 id="org7bf71e9">allocate-conjugate-local-memory</h3>
<div class="outline-text-3" id="text-org7bf71e9">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =64bit, machine {

define_primitive_function <span style="color: #e6db74;">"allocate-conjugate-local-memory"</span>, allocate_conjugate_local_memory
   <span style="color: #FF8888;">;; &lt;&lt; size -- address &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, pointer$return_stack
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">rax</span>, address$return_stack
   <span style="color: #a6e22e;">test</span> <span style="color: #fd971f;">rax</span>, unit__return_point
   <span style="color: #a6e22e;">jnz</span> .return_stack_even

   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [V__local_memory_even__current_free_address + cell_size]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">add</span> [V__local_memory_even__current_free_address + cell_size], <span style="color: #fd971f;">rbx</span>
   next

<span style="color: #a6e22e;">.return_stack_even</span>:
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [V__local_memory_odd__current_free_address + cell_size]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">add</span> [V__local_memory_odd__current_free_address + cell_size], <span style="color: #fd971f;">rbx</span>
   next

}

<span style="color: #a6e22e;">match</span> =32bit, machine {

define_primitive_function <span style="color: #e6db74;">"allocate-conjugate-local-memory"</span>, allocate_conjugate_local_memory
   <span style="color: #FF8888;">;; &lt;&lt; size -- address &gt;&gt;</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [pointer$return_stack]
   <span style="color: #a6e22e;">sub</span> <span style="color: #fd971f;">rax</span>, address$return_stack
   <span style="color: #a6e22e;">test</span> <span style="color: #fd971f;">rax</span>, unit__return_point
   <span style="color: #a6e22e;">jnz</span> .return_stack_even

   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [V__local_memory_even__current_free_address + cell_size]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">add</span> [V__local_memory_even__current_free_address + cell_size], <span style="color: #fd971f;">rbx</span>
   next

<span style="color: #a6e22e;">.return_stack_even</span>:
   pop_argument_stack <span style="color: #fd971f;">rbx</span>
   <span style="color: #a6e22e;">mov</span> <span style="color: #fd971f;">rax</span>, [V__local_memory_odd__current_free_address + cell_size]
   push_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">add</span> [V__local_memory_odd__current_free_address + cell_size], <span style="color: #fd971f;">rbx</span>
   next

}
</pre>
</div>
</div>
</div>

<div id="outline-container-orgf632b10" class="outline-3">
<h3 id="orgf632b10"><span class="done test">test</span> </h3>
<div class="outline-text-3" id="text-orgf632b10">
<div class="org-src-container">

<pre class="src src-cicada-nymph"><span style="color: #ffff00; font-weight: bold;">:</span> <span style="color: #ef5939; font-weight: bold;">test,allocate-local-memory</span>
  <span style="color: #FF8888;">&lt;&lt; -- address, address &gt;&gt;</span>
  <span style="color: #fd971f; font-weight: bold;">16</span> <span style="color: #AE7C3B; font-weight: bold;">allocate-local-memory</span>
  <span style="color: #fd971f; font-weight: bold;">16</span> <span style="color: #AE7C3B; font-weight: bold;">allocate-local-memory</span>
  <span style="color: #00ffff; font-weight: bold;">end</span>
<span style="color: #ffff00; font-weight: bold;">;</span> <span style="color: #ae81ff; font-weight: bold;">define-function</span>
test,allocate-local-memory

<span style="color: #FF8888;">&lt;&lt;</span>
<span style="color: #FF8888;">40218513</span>
<span style="color: #FF8888;">40218529</span>
<span style="color: #FF8888;">&gt;&gt;</span>

<span style="color: #ffff00; font-weight: bold;">:</span> <span style="color: #ef5939; font-weight: bold;">test,allocate-local-memory,2</span>
  <span style="color: #FF8888;">&lt;&lt; -- address, address &gt;&gt;</span>
  <span style="color: #fd971f; font-weight: bold;">16</span> <span style="color: #AE7C3B; font-weight: bold;">allocate-local-memory</span>
  test,allocate-local-memory
  <span style="color: #fd971f; font-weight: bold;">16</span> <span style="color: #AE7C3B; font-weight: bold;">allocate-local-memory</span>
  test,allocate-local-memory
  <span style="color: #fd971f; font-weight: bold;">16</span> <span style="color: #AE7C3B; font-weight: bold;">allocate-local-memory</span>
  <span style="color: #00ffff; font-weight: bold;">end</span>
<span style="color: #ffff00; font-weight: bold;">;</span> <span style="color: #ae81ff; font-weight: bold;">define-function</span>
test,allocate-local-memory,2

<span style="color: #FF8888;">&lt;&lt;</span>
<span style="color: #FF8888;">40218513</span>
<span style="color: #FF8888;">  40218529</span>
<span style="color: #FF8888;">  40218545</span>
<span style="color: #FF8888;">40218529</span>
<span style="color: #FF8888;">  40218545</span>
<span style="color: #FF8888;">  40218561</span>
<span style="color: #FF8888;">40218545</span>
<span style="color: #FF8888;">&gt;&gt;</span>
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-orgc78f3ba" class="outline-2">
<h2 id="orgc78f3ba">syscall</h2>
<div class="outline-text-2" id="text-orgc78f3ba">
</div><div id="outline-container-orga79c513" class="outline-3">
<h3 id="orga79c513"><span class="todo note">note</span> </h3>
<div class="outline-text-3" id="text-orga79c513">
<ul class="org-ul">
<li><p>there are two ways to treat the syscall</p><p><ol class="org-ol"></p><p><li>syscall is NOT expose to cicada-nymph</p><p>system functions are wraped in assembly code</p><p>thus</p><p>make cicada-nymph code be more clean</li></p><p><li>syscall is expose to cicada-nymph</p><p>system functions are wraped in cicada-nymph code</p><p>thus</p><p>more easy to wraped more system functions</p><p>and</p><p>make assembly code be more clean</p><p>[only needs some system functions to load core file]</li></ol></p></li>
<li><p>I choose the second way for now</p></li></ul>
</div>
</div>

<div id="outline-container-org5c326ed" class="outline-3">
<h3 id="org5c326ed">string-&gt;syscall-string</h3>
<div class="outline-text-3" id="text-org5c326ed">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">string$string_to_syscall_string</span>:
   <span style="color: #f92672; font-weight: bold;">times</span> <span style="color: #ae81ff;">256</span> <span style="color: #66d9ef; font-weight: bold;">db</span> <span style="color: #ae81ff;">0</span>

define_function <span style="color: #e6db74;">"string-&gt;syscall-string"</span>, string_to_syscall_string
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- syscall-string[address] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, string$string_to_syscall_string
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   addition
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">0</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   swap, set_byte
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, string$string_to_syscall_string
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string_to_buffer!
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, string$string_to_syscall_string
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org8cbd323" class="outline-3">
<h3 id="org8cbd323">string-&gt;syscall-string-2</h3>
<div class="outline-text-3" id="text-org8cbd323">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">string$string_to_syscall_string_2</span>:
   <span style="color: #f92672; font-weight: bold;">times</span> <span style="color: #ae81ff;">256</span> <span style="color: #66d9ef; font-weight: bold;">db</span> <span style="color: #ae81ff;">0</span>

define_function <span style="color: #e6db74;">"string-&gt;syscall-string-2"</span>, string_to_syscall_string_2
   <span style="color: #FF8888;">;; &lt;&lt; string[address, length] -- syscall-string[address] &gt;&gt;</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">dup</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, string$string_to_syscall_string_2
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   addition
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   <span style="color: #f92672; font-weight: bold;">literal</span>, <span style="color: #ae81ff;">0</span>
   <span style="color: #66d9ef; font-weight: bold;">xx</span>   swap, set_byte
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, string$string_to_syscall_string_2
   <span style="color: #66d9ef; font-weight: bold;">xx</span> string_to_buffer!
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, string$string_to_syscall_string_2
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>
</pre>
</div>
</div>
</div>

<div id="outline-container-org3895db0" class="outline-3">
<h3 id="org3895db0">syscall&#xa0;&#xa0;&#xa0;<span class="tag"><span class="64bit">64bit</span>&#xa0;<span class="linux">linux</span></span></h3>
<div class="outline-text-3" id="text-org3895db0">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =linux =64bit, platform machine {

define_primitive_function <span style="color: #e6db74;">"syscall"</span>, CICADA__syscall
   <span style="color: #FF8888;">;; &lt;&lt; ..., argument2, argument1,</span>
   <span style="color: #FF8888;">;;    syscall-number,</span>
   <span style="color: #FF8888;">;;    number-of-arguments</span>
   <span style="color: #FF8888;">;;    -- return-value &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">cmp</span> <span style="color: #fd971f;">rax</span>, <span style="color: #ae81ff;">0</span>
   <span style="color: #a6e22e;">je</span> __syscall_with_0
   <span style="color: #a6e22e;">cmp</span> <span style="color: #fd971f;">rax</span>, <span style="color: #ae81ff;">1</span>
   <span style="color: #a6e22e;">je</span> __syscall_with_1
   <span style="color: #a6e22e;">cmp</span> <span style="color: #fd971f;">rax</span>, <span style="color: #ae81ff;">2</span>
   <span style="color: #a6e22e;">je</span> __syscall_with_2
   <span style="color: #a6e22e;">cmp</span> <span style="color: #fd971f;">rax</span>, <span style="color: #ae81ff;">3</span>
   <span style="color: #a6e22e;">je</span> __syscall_with_3
   <span style="color: #a6e22e;">cmp</span> <span style="color: #fd971f;">rax</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #a6e22e;">je</span> __syscall_with_4
   <span style="color: #a6e22e;">cmp</span> <span style="color: #fd971f;">rax</span>, <span style="color: #ae81ff;">5</span>
   <span style="color: #a6e22e;">je</span> __syscall_with_5
   <span style="color: #a6e22e;">cmp</span> <span style="color: #fd971f;">rax</span>, <span style="color: #ae81ff;">6</span>
   <span style="color: #a6e22e;">je</span> __syscall_with_6
   <span style="color: #a6e22e;">jmp</span> __syscall_with_too_many

__syscall_with_0:
   pop_argument_stack linux64_sys_n_rax
   <span style="color: #a6e22e;">syscall</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

__syscall_with_1:
   pop_argument_stack linux64_sys_n_rax
   pop_argument_stack linux64_sys_1_rdi
   <span style="color: #a6e22e;">syscall</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

__syscall_with_2:
   pop_argument_stack linux64_sys_n_rax
   pop_argument_stack linux64_sys_1_rdi
   pop_argument_stack linux64_sys_2_rsi
   <span style="color: #a6e22e;">syscall</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

__syscall_with_3:
   pop_argument_stack linux64_sys_n_rax
   pop_argument_stack linux64_sys_1_rdi
   pop_argument_stack linux64_sys_2_rsi
   pop_argument_stack linux64_sys_3_rdx
   <span style="color: #a6e22e;">syscall</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

__syscall_with_4:
   pop_argument_stack linux64_sys_n_rax
   pop_argument_stack linux64_sys_1_rdi
   pop_argument_stack linux64_sys_2_rsi
   pop_argument_stack linux64_sys_3_rdx
   pop_argument_stack linux64_sys_4_r10
   <span style="color: #a6e22e;">syscall</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

__syscall_with_5:
   pop_argument_stack linux64_sys_n_rax
   pop_argument_stack linux64_sys_1_rdi
   pop_argument_stack linux64_sys_2_rsi
   pop_argument_stack linux64_sys_3_rdx
   pop_argument_stack linux64_sys_4_r10
   pop_argument_stack linux64_sys_5_r9
   <span style="color: #a6e22e;">syscall</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

__syscall_with_6:
   pop_argument_stack linux64_sys_n_rax
   pop_argument_stack linux64_sys_1_rdi
   pop_argument_stack linux64_sys_2_rsi
   pop_argument_stack linux64_sys_3_rdx
   pop_argument_stack linux64_sys_4_r10
   pop_argument_stack linux64_sys_5_r9
   pop_argument_stack linux64_sys_6_r8
   <span style="color: #a6e22e;">syscall</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

__syscall_with_too_many:
   <span style="color: #a6e22e;">call</span> __exit_with_six

}
</pre>
</div>
</div>
</div>

<div id="outline-container-org799e6a1" class="outline-3">
<h3 id="org799e6a1">syscall&#xa0;&#xa0;&#xa0;<span class="tag"><span class="32bit">32bit</span>&#xa0;<span class="linux">linux</span></span></h3>
<div class="outline-text-3" id="text-org799e6a1">
<div class="org-src-container">

<pre class="src src-fasm"><span style="color: #a6e22e;">match</span> =linux =32bit, platform machine {

define_primitive_function <span style="color: #e6db74;">"syscall"</span>, CICADA__syscall
   <span style="color: #FF8888;">;; &lt;&lt; ..., argument2, argument1,</span>
   <span style="color: #FF8888;">;;    syscall-number,</span>
   <span style="color: #FF8888;">;;    number-of-arguments</span>
   <span style="color: #FF8888;">;;    -- return-value &gt;&gt;</span>
   pop_argument_stack <span style="color: #fd971f;">rax</span>
   <span style="color: #a6e22e;">cmp</span> <span style="color: #fd971f;">rax</span>, <span style="color: #ae81ff;">0</span>
   <span style="color: #a6e22e;">je</span> __syscall_with_0
   <span style="color: #a6e22e;">cmp</span> <span style="color: #fd971f;">rax</span>, <span style="color: #ae81ff;">1</span>
   <span style="color: #a6e22e;">je</span> __syscall_with_1
   <span style="color: #a6e22e;">cmp</span> <span style="color: #fd971f;">rax</span>, <span style="color: #ae81ff;">2</span>
   <span style="color: #a6e22e;">je</span> __syscall_with_2
   <span style="color: #a6e22e;">cmp</span> <span style="color: #fd971f;">rax</span>, <span style="color: #ae81ff;">3</span>
   <span style="color: #a6e22e;">je</span> __syscall_with_3
   <span style="color: #a6e22e;">cmp</span> <span style="color: #fd971f;">rax</span>, <span style="color: #ae81ff;">4</span>
   <span style="color: #a6e22e;">je</span> __syscall_with_4
   <span style="color: #a6e22e;">cmp</span> <span style="color: #fd971f;">rax</span>, <span style="color: #ae81ff;">5</span>
   <span style="color: #a6e22e;">je</span> __syscall_with_5
   <span style="color: #a6e22e;">jmp</span> __syscall_with_too_many

__syscall_with_0:
   pop_argument_stack linux32_sys_n_eax
   <span style="color: #a6e22e;">syscall</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

__syscall_with_1:
   pop_argument_stack linux32_sys_n_eax
   pop_argument_stack linux32_sys_1_ebx
   <span style="color: #a6e22e;">syscall</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

__syscall_with_2:
   pop_argument_stack linux32_sys_n_eax
   pop_argument_stack linux32_sys_1_ebx
   pop_argument_stack linux32_sys_2_ecx
   <span style="color: #a6e22e;">syscall</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

__syscall_with_3:
   pop_argument_stack linux32_sys_n_eax
   pop_argument_stack linux32_sys_1_ebx
   pop_argument_stack linux32_sys_2_ecx
   pop_argument_stack linux32_sys_3_edx
   <span style="color: #a6e22e;">syscall</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

__syscall_with_4:
   pop_argument_stack linux32_sys_n_eax
   pop_argument_stack linux32_sys_1_ebx
   pop_argument_stack linux32_sys_2_ecx
   pop_argument_stack linux32_sys_3_edx
   pop_argument_stack linux32_sys_4_esi
   <span style="color: #a6e22e;">syscall</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

__syscall_with_5:
   pop_argument_stack linux32_sys_n_eax
   pop_argument_stack linux32_sys_1_ebx
   pop_argument_stack linux32_sys_2_ecx
   pop_argument_stack linux32_sys_3_edx
   pop_argument_stack linux32_sys_4_esi
   pop_argument_stack linux32_sys_5_edi
   <span style="color: #a6e22e;">syscall</span>
   push_argument_stack <span style="color: #fd971f;">rax</span>
   next

__syscall_with_too_many:
   <span style="color: #a6e22e;">call</span> __exit_with_six

}
</pre>
</div>
</div>
</div>
</div>


<div id="outline-container-org288a128" class="outline-2">
<h2 id="org288a128">epilog</h2>
<div class="outline-text-2" id="text-org288a128">
</div><div id="outline-container-orgeed509d" class="outline-3">
<h3 id="orgeed509d">constant</h3>
<div class="outline-text-3" id="text-orgeed509d">
<div class="org-src-container">

<pre class="src src-fasm">define_variable <span style="color: #e6db74;">"*explainer,function*"</span>, CICADA__explain$function
   <span style="color: #66d9ef; font-weight: bold;">xx</span> explain$function

define_variable <span style="color: #e6db74;">"*explainer,variable*"</span>, CICADA__explain$variable
   <span style="color: #66d9ef; font-weight: bold;">xx</span> explain$variable
</pre>
</div>
</div>
</div>

<div id="outline-container-org4d234b6" class="outline-3">
<h3 id="org4d234b6">platform</h3>
<div class="outline-text-3" id="text-org4d234b6">
<ul class="org-ul">
<li><p>this word is implemented as a function</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">define_function <span style="color: #e6db74;">"platform"</span>, the_platform
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, string$platform
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">literal</span>, length$platform
   <span style="color: #66d9ef; font-weight: bold;">xx</span> <span style="color: #f92672; font-weight: bold;">end</span>

<span style="color: #a6e22e;">string$platform</span>:

<span style="color: #a6e22e;">match</span> =linux, platform {
   <span style="color: #66d9ef; font-weight: bold;">db</span> <span style="color: #e6db74;">"linux"</span>
}

<span style="color: #a6e22e;">.end</span>:
length$platform = (.end - string$platform)
</pre>
</div>
</div>
</div>

<div id="outline-container-org5849a23" class="outline-3">
<h3 id="org5849a23"><b>un-initialized-memory</b></h3>
<div class="outline-text-3" id="text-org5849a23">
<div class="org-src-container">

<pre class="src src-fasm">define_variable <span style="color: #e6db74;">"*un-initialized-memory*"</span>, V__un_initialized_memory
  <span style="color: #66d9ef; font-weight: bold;">xx</span> address$un_initialized_memory

define_variable <span style="color: #e6db74;">"*un-initialized-memory,size*"</span>, V__un_initialized_memory__size
  <span style="color: #66d9ef; font-weight: bold;">xx</span> size$un_initialized_memory

define_variable <span style="color: #e6db74;">"*un-initialized-memory,current-free-address*"</span>, V__un_initialized_memory__current_free_address
  <span style="color: #66d9ef; font-weight: bold;">xx</span> current_free_address$un_initialized_memory
</pre>
</div>
</div>
</div>

<div id="outline-container-orgdf8e3c1" class="outline-3">
<h3 id="orgdf8e3c1"><b>string-area,current-free-address</b></h3>
<div class="outline-text-3" id="text-orgdf8e3c1">
<ul class="org-ul">
<li><p>the last_name_string_in_assembly</p><p>is just "<b>string-area,current-free-address</b>"</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">define_variable <span style="color: #e6db74;">"*string-area,current-free-address*"</span>, V__string_area__current_free_address
   <span style="color: #66d9ef; font-weight: bold;">xx</span> current_free_address$string_area
</pre>
</div>
</div>
</div>

<div id="outline-container-org6fe77cc" class="outline-3">
<h3 id="org6fe77cc">the_last_link_in_assembly_code</h3>
<div class="outline-text-3" id="text-org6fe77cc">
<ul class="org-ul">
<li><p>this word helps to initialize V__link</p></li></ul>
<div class="org-src-container">

<pre class="src src-fasm">the_last_link_in_assembly_code = link
</pre>
</div>
</div>
</div>

<div id="outline-container-org3f62ef" class="outline-3">
<h3 id="org3f62ef">un_initialized_memory&#xa0;&#xa0;&#xa0;<span class="tag"><span class="linux">linux</span></span></h3>
<div class="outline-text-3" id="text-org3f62ef">
<div class="org-src-container">

<pre class="src src-fasm">size$un_initialized_memory = <span style="color: #ae81ff;">88</span> * <span style="color: #ae81ff;">1024</span> * <span style="color: #ae81ff;">1024</span> <span style="color: #FF8888;">;; (byte)</span>

<span style="color: #a6e22e;">match</span> =linux, platform {

<span style="color: #f92672; font-weight: bold;">segment</span> <span style="color: #f92672; font-weight: bold;">readable</span> <span style="color: #f92672; font-weight: bold;">writeable</span>
<span style="color: #a6e22e;">address$un_initialized_memory</span>:
   <span style="color: #66d9ef; font-weight: bold;">rb</span> size$un_initialized_memory

}
</pre>
</div>
</div>
</div>
</div>
</div>
<div id="postamble" class="status">
近死之心 莫使復陽也
</div>
</body>
</html>
